在angular-cli项目中使用mdc sass文件

时间:2017-10-23 10:48:26

标签: css sass angular-cli sass-loader mdc-components

我有一个使用angular-cli的项目。我正在使用mdc components /。我想导入单个组件的sass文件。为此,

1)我已使用此命令更改了默认的styleExt

ng set defaults.styleExt scss

2)将文件style.css重命名为style.scss

3)在angular-cli.json已更改

"styles": [
        "styles.css"
      ],

"styles": [
        "styles.scss"
      ],

4)添加stylePreprocessorOptions配置以包含路径

"stylePreprocessorOptions": {
        "includePaths": [
          "node_modules"
        ]
 }

5)最后在style.scss文件中导入

@import '~@material/button/mdc-button';

但是显示

ERROR in ./~/css-loader?{"sourceMap":false,"importLoaders":1}!./~/postcss-loader?{"ident":"postcss"}!./~/sass-loader/lib/loader.js?{"sourceMap":false,"precis
ion":8,"includePaths":["D://SK//Study//Material//MaterialWithAngularDemo//src//node_modules"]}!./src/styles.scss
Module build failed:
undefined
^
      File to import not found or unreadable: @material/theme/mixins.
Parent style sheet: D:/SK/Study/Material/MaterialWithAngularDemo/node_modules/@material/button/mdc-button.scss
      in D:\SK\Study\Material\MaterialWithAngularDemo\node_modules\@material\button\mdc-button.scss (line 17, column 1)
 @ ./src/styles.scss 4:14-187
 @ multi ./src/styles.scss

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

includePath而不是node_modules错误应该是../node_modules

"stylePreprocessorOptions": {
        "includePaths": [
          "../node_modules"
        ]
 }

更改后,它工作正常。