For Angular 6判断Official documentation
Note:对于早于6.0.0-beta.6
的@angular/cli
版本,请使用ng set
代替ng config
.
对于现有项目
在使用默认css
种样式设置的现有angular cli项目中,您需要做几件事:
- 将默认样式扩展名更改为
scss
手动更改.angular-cli.json
(Angular 5.x及更早版本)或angular.json
(Angular 6+)或运行:
ng config defaults.styleExt=scss
如果收到错误:Value cannot be found.
,请使用以下命令:
ng config schematics.@schematics/angular:component.styleext scss
个
(*来源:Angular CLI SASS options)
将现有的.css
个文件重命名为.scss
(即style es.css和app/app.Component.css)
指向CLI以查找style es.scss
手动更改angular.json
中apps[0].styles
中的文件扩展名
- 指向组件以查找新样式文件
更改组件中的styleUrls
以匹配新文件名
对于future 的项目
正如@Serginho提到的,在运行ng new
命令时,可以设置样式扩展
ng new your-project-name --style=scss
如果要为将来创建的所有项目设置默认值,请运行以下命令:
ng config --global defaults.styleExt=scss