在自定义角度库中使用Postcss [英] Use Postcss in Custom Angular Library

查看:141
本文介绍了在自定义角度库中使用Postcss的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了 postcss posthtml-css-modules 以在Angular应用程序中实现CSS模块.我还使用了 @ angular-builders/custom-webpack 实现.

I used postcss, postcss-css-modules and posthtml-css-modules to implement CSS Modules in a Angular Application. I also used @angular-builders/custom-webpack to achieved this.

现在,我想对自定义角度库"进行同样的操作.但是,我不能使用 @angular -builders/custom-webpack ,因为Angular库是使用 ng-packagr .

Now, I want to do the same with my Custom Angular Library. However, I cannot use @angular-builders/custom-webpack because the Angular Libraries are build using ng-packagr.

因此, @angular -builders/custom-webpack 无法使用: https://github.com/just-jeb/angular-builders/issues/356

另一方面, ng-packa 不支持我已阅读到可以扩展汇总配置(使用

I have read that it's possible to extend rollup config (is the compiler that use ng-packagr at the end of the build) in ng-packagr:

https://github.com. com/ng-packagr/ng-packagr/blob/master/docs/DESIGN.md#rollup-config

但是我没有找到任何文档来实现这一目标.

But I didn't find any documentation to achieve this.

有人知道怎么做吗?

我认为的其他解决方案是,使所有样式变为全局样式,并使用 scss-bundle 和postcss,就像我在这里所做的:

Other solution that I thought, it's make all the styles global and compile them using scss-bundle and postcss like I did here: NodeJs Script that compiles scss files fails because of postcss rule for undefined variables

如果我可以使用 lodash 之后,我将能够用其哈希类替换类名此处建议使用类似的名称:在JavaScript/TypeScript文件中使用[hash:base64:5]

And after If I can use lodash I will be able to replace the class names by their hashed class name like is proposed here: Use [hash:base64:5] in JavaScript / TypeScript file

但是要做到这一点,我将需要知道如何在 ng- packagr .

But to do that, I will need to know how to invoke lodash in the build of ng-packagr.

有人知道怎么做吗?

任何其他解决方案都值得欢迎.

Any other solution is more than welcome.

先谢谢了.

推荐答案

已经有关于此增强功能的讨论.可能变化仍在进行中.您可以在此处

There is already a discussion going on this enhancement. May be changes are still in progress. You can track from here

您可以预处理您的样式,然后按照此

You can pre-process your styles and then pass to ng-packagr as suggested by this article

嵌入HTML文件的其他问题,您可以使用它来创建类似工具

Other problem to embed with HTML files you can use create a post build process something like this with help of these tools

我希望这可以解决您的问题.

I hope this solves your problem.

这篇关于在自定义角度库中使用Postcss的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆