0

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

1) 我已经使用这个命令改变了默认的 styleExt

ng set defaults.styleExt scss

2) 将文件重命名style.cssstyle.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

我错过了什么吗?

4

1 回答 1

0

有一个错误,includePath而不是node_modules应该是../node_modules

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

更改后,它工作正常。

于 2017-10-23T11:02:29.373 回答