首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角-cli:将sass加载程序配置为在node_modules中包含includePath。

角-cli:将sass加载程序配置为在node_modules中包含includePath。
EN

Stack Overflow用户
提问于 2016-09-22 09:59:38
回答 2查看 4.4K关注 0票数 3

角-cli:1.0.0-β.15

节点: 6.5.0

操作系统: linux x64

我想从bootstrap-material-design v4-dev分支编译scss文件,方法是将它放在angular-cli.json的apps.styles[]数组中,但是我得到了以下错误:

代码语言:javascript
复制
ERROR in ./~/css-loader!./~/postcss-loader!./~/sass-loader!./~/bootstrap-material-design/scss/bootstrap-material-design.scss                                               
Module build failed:                                                                                                                                                       
@import "bootstrap/scss/variables"; // from bootstrap node_module                                                                                                          
^                                                                                                                                                                          
      File to import not found or unreadable: bootstrap/scss/variables                                                                                                     
Parent style sheet: /home/ciesielskico/Documents/Git/reports/node_modules/bootstrap-material-design/scss/_variables.scss                
      in /home/ciesielskico/Documents/Git/reports/node_modules/bootstrap-material-design/scss/_variables.scss (line 45, column 1)       
 @ ./~/bootstrap-material-design/scss/bootstrap-material-design.scss 4:14-148                                                                                              
 @ multi styles

angular-cli.json

代码语言:javascript
复制
"styles": [
                "../node_modules/bootstrap/scss/bootstrap-flex.scss",
                "../node_modules/bootstrap-material-design/scss/bootstrap-material-design.scss",
]

在引导材料设计的文档中,它说要将node_modules放在sass-加载程序的includePath中。

用目前版本的角质cli可以吗?如果是,怎么做?

EN

回答 2

Stack Overflow用户

发布于 2016-09-27 13:48:41

解决办法

我编写了一个节点脚本,作为执行。位于webpack-build-production.jswebpack-build-development.js的文件node_modules/angular-cli/models/应该包含sassLoader实体,下面的脚本将自动地追加它。

代码语言:javascript
复制
var fs = require('fs');

const FILES = [
  "node_modules/angular-cli/models/webpack-build-production.js",
  "node_modules/angular-cli/models/webpack-build-development.js"
];

const ADDITIONAL_LINES = "\
        ,sassLoader: {\n\
            includePaths: [path.resolve(\"node_modules/bootstrap-sass/assets/stylesheets\")]\n\
        }\n\
    };\n";


FILES.forEach(function (file) {
  var text = fs.readFileSync(file, "utf8");
  var alreadyEdited = false;
  var content = "";

  text.split(/\r?\n/).forEach(function (line) {
    if (line.indexOf('sassLoader') !== -1) {
      alreadyEdited = true;
    }

    if (line.indexOf(' };') !== -1) {
      content += ADDITIONAL_LINES;
    } else {
      content += line + "\n";
    }
  });

  if (!alreadyEdited) {
    console.log('File is being adjusted by fix script. ', file);
    fs.writeFileSync(file, content, 'utf8');
  }
});
票数 3
EN

Stack Overflow用户

发布于 2016-11-09 19:35:37

不确定你是否有这方面的工作,但任何人谁正在寻找(ng-cli与启动和SCSS)。

请查看此SO question,并将预处理器默认样式扩展设置为scss

不需要安装Node-sass或任何其他加载程序。它使用的是对默认扩展的小修改。

然后可以在styles.scss中将引导样式添加为导入。(只需更改默认styles.css的扩展)

styles.scss

代码语言:javascript
复制
@import "../node_modules/bootstrap/scss/bootstrap.scss";

还可以将其添加到app.component.ts中作为styleUrls: ['./app.component.css', '../../node_modules/bootstrap/scss/bootstrap.scss'],并将encapsulation: ViewEncapsulation.None添加到组件注释中以全局应用引导。

我更喜欢styles.scss方法,因为我认为这个文件是针对全局样式的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39635971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档