编辑 Angular 6+
Found on GitHub page of Angular:
stylePreprocessorOptions 仍受支持。不过,您将不得不手动更新新生成的angular.json。它的新位置在 json 的“选项”块内。
示例配置可能如下所示:
"options": {
"outputPath": "../webapp",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": [
{
"glob": "**/*",
"input": "src/resources",
"output": "/resources"
},
],
"styles": [
"src/styles.scss"
],
"stylePreprocessorOptions": {
"includePaths": [
"src/styles"
]
},
"scripts": []
}
注意改变的路径。
原始答案
实际上,通过将"styleExt" 设置为"css",它开箱即用就可以了。特定模块中的一堆组件正在使用 SASS。我有一个包含变量和 mixins 的 sass 文件夹,angular-cli.json 中的这个设置是正确编译/处理这些 scss 文件所必需的:
"stylePreprocessorOptions": {
"includePaths": [
"sass"
]
}
混合使用 css 和 scss 文件时,应用程序可以很好地呈现。我假设在通过angular-cli 命令添加组件时,此styleExt 参数仅用于生成默认组件样式 (css, scss, less) 文件。