在 Angular 6+ (styleExt) 中使用 scss 作为默认样式表 [英] Using scss as default style sheet in Angular 6+ (styleExt)
问题描述
显然,从 Angular 6 开始,声明默认样式表扩展的方式发生了变化.angular.json
中的 styleExt
属性不再被识别.
Apparently the way to declare the default stylesheet extension changed from Angular 6 onwards. The styleExt
property in the angular.json
is not recognised any longer.
对于新项目,这可以通过 new
命令的 CLI --style=scss
选项设置.
For new projects this can be set with an option on the CLI --style=scss
on the new
command.
但是,对于我从 Angular <5 迁移的现有项目,或者如果您在项目创建过程中忘记这样做,您如何更改此设置?
However, how do you change this for exsting projects that I migrate from Angular <5 or if you forgot to do this during project creation?
这个问题与 Angular 5 到 6 版本的重大变化密切相关.
This question is meant to be strictly related to the breaking changes by the version 5 to 6 of Angular.
推荐答案
在 angular.json
中设置的位置发生了变化.现在有两种方法可以设置此选项.
The position on which this is set changed in the angular.json
. There are 2 ways to set this option now.
通过 Angular CLI:
Via the Angular CLI:
ng config schematics.@schematics/angular:component.styleext scss
直接在angular.json
中:
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
}
Angular 9 更新:
请注意,从 Angular 9 开始,styleext
被重命名为 style
.所以我们最终得到:
Angular 9 Update:
Note that from Angular 9 onwards styleext
is renamed to style
. So we end up with:
ng config schematics.@schematics/angular:component.style scss
和
"schematics": {
"@schematics/angular:component": {
"style": "scss"
}
}
这篇关于在 Angular 6+ (styleExt) 中使用 scss 作为默认样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!