当我使用 Angular 5 CLI 来生成新组件时(例如 ng g c my-component),它将创建4个文件(html、css、ts、spec.ts)。我更希望为该组件也(或仅)创建一个 *.less 文件。我不确定 Angular 存储文件列表或用于生成新文件的模板的位置。我是否可以添加自己的文件类型以由 CLI 生成?
--style
选项将默认样式格式设置为less。ng new new-app --style=less
defaults
部分,并将 styleExt
的值更改为 less
。请参见以下内容。"defaults": {
"styleExt": "less",
"component": {}
}
就是这样了!
对于Angular 8,请在您的angular.json中使用以下设置
"@schematics/angular:component": {
"style": "less"
}
例子:
"YOURAppName": {
"projectType": "application",
"schematics": {
"@schematics/angular:component": {
"style": "less"
}
},
"root": "",
"sourceRoot": "src",
"prefix": "app",
对于Angular 9及以上版本,请使用“style”代替(“styleext”或“styleExt”)
在angular.json
中:
"@schematics/angular:component": {
"style": "less"
}
"@schematics/angular:component": {
"styleext": "less"
}