Angular CLI 使用 SASS 生成库 [英] Angular CLI Generate Library with SASS
问题描述
我有一个 Angular6 应用程序,我正在尝试为其创建一个库.我能够生成一个库项目,但是当我为库生成组件时,Angular CLI 正在使用 .css 文件创建它.
I have an Angular6 app that I am trying to create a library for. I was able to generate a library project but when I generate the component for the library, Angular CLI is creating it with .css files.
如何让它创建 .scss 文件?
How can I get it to create .scss files?
以下是我用来创建项目的命令:
Here are the commands I'm using to create the project:
ng new example-app --style=scss
rename example-app example
cd example
ng generate library example --prefix=exam --style=scss
ng generate component test --project=example
ng generate library
命令中的 --style=scss
选项不起作用,我的测试组件文件夹中仍然有 CSS 文件.
The --style=scss
option on the ng generate library
command does not have an effect, I still get CSS files in my test component folder.
推荐答案
您可以通过在您的 angular.json
中覆盖您的项目的 schematics
来修复它,就像在示例中一样下面:
You can fix it by overriding schematics
for your project in your angular.json
like in the example below:
"example": {
"root": "projects/example",
"sourceRoot": "projects/example/src",
"projectType": "library",
"prefix": "exam",
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
},
....
}
或者你可以像这样通过 angular-cli 设置这个值:
or you can set this value via angular-cli like so:
ng config schematics.@schematics/angular:component.styleext scss
然后尝试生成组件,它应该有 scss
扩展名.
After that try to generate component, it should have scss
extension.
EDIT(用 style
替换 styleExt
):
EDIT (replace styleExt
with style
):
根据这个关闭的票 https://github.com/ngrx/platform/issues/2248 使用新版本的 Angular CLI styleExt
已替换为 style
- 我在两个使用 Angular anf Angular CLI 版本 8 的库中对其进行了测试.
As per this closed ticket https://github.com/ngrx/platform/issues/2248 with new version of Angular CLI styleExt
has been replaced with style
- I tested it in two libraries that are using Angular anf Angular CLI versions 8.
这篇关于Angular CLI 使用 SASS 生成库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!