将node-sass-json-importer集成到Angular CLI应用程序中 [英] Integrate node-sass-json-importer into an Angular CLI application
问题描述
尝试将 node-sass-json-importer 添加到Angular中CLI应用程序.
Trying to add the node-sass-json-importer into an Angular CLI application.
我正在使用CLI的版本1.0.0-beta.17
,但是也无法使用当前版本的1.2
来弄清楚它.通过纱安装后,我不知道应在应用程序配置中将其设置在何处.
I was using version 1.0.0-beta.17
of the CLI, but haven't been able to figure it out using the current version 1.2
either. After installing it via yarn I don't know where it should be setup in the application configuration.
有人成功将其集成到他们的应用程序中吗?我可以找到关于唯一的答案,该答案仅适用于使用Webpack的应用程序,而不适用于Angular CLI.
Has anyone successfully integrated this into their application? The only answer I could find regarding this is for applications using Webpack, but not for the Angular CLI.
推荐答案
通过更改styles.js解决了此问题
Solved this by changing the styles.js
node_modules/@angular/cli/models/webpack-configs/styles.js
在上述文件中,按如下所述进行编辑
In the above file , edit as mentioned below
const jsonImporter = require('node-sass-json-importer');
并在.scss规则中添加importer:jsonImporter
and add importer: jsonImporter in the rule for .scss
{ test: /\.scss$|\.sass$/, use: [{
loader: 'sass-loader',
options: {
sourceMap: cssSourceMap,
// bootstrap-sass requires a minimum precision of 8
precision: 8,
includePaths,
importer: jsonImporter,
}
}]
}
这可能不是最好的解决方案,但可以解决您的问题,在这种情况下,我看不到将args传递给node-sass的选项,这是--importer'./node_modules/node-sass-json-进口商",
This might not be the best solution but solves your issue , there is no option i can see to pass the args to node-sass here in this case it is --importer './node_modules/node-sass-json-importer' ,
根据此链接 https://github.com/angular/angular-cli/issues/1791 它仅允许单独的includePaths选项.
as per this link https://github.com/angular/angular-cli/issues/1791 it allows only includePaths option alone.
希望这会有所帮助!
这篇关于将node-sass-json-importer集成到Angular CLI应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!