简体   繁体   English

将node-sass-json-importer集成到Angular CLI应用程序中

[英]Integrate node-sass-json-importer into an Angular CLI application

Trying to add the node-sass-json-importer into an Angular CLI application. 尝试将node-sass-json-importer添加到Angular CLI应用程序中。

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. 我使用的是CLI的1.0.0-beta.17版本,但是使用当前版本1.21.0.0-beta.17这个问题。 After installing it via yarn I don't know where it should be setup in the application configuration. 通过纱线安装后,我不知道应该在应用程序配置中设置它。

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. 我能找到的唯一答案是使用Webpack的应用程序,而不是Angular CLI。

Solved this by changing the styles.js 通过更改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');

and add importer: jsonImporter in the rule for .scss 并在.scss规则中添加importer:jsonImporter

{ test: /\.scss$|\.sass$/, use: [{
                    loader: 'sass-loader',
                    options: {
                        sourceMap: cssSourceMap,
                        // bootstrap-sass requires a minimum precision of 8
                        precision: 8,
                        includePaths,
                        importer: jsonImporter,
                    }
                }]
        }

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' , 这可能不是最好的解决方案但是解决了你的问题,我没有看到将args传递给node-sass的选项,在这种情况下它是--importer'./node_modules/node-sass-json-importer',

as per this link https://github.com/angular/angular-cli/issues/1791 it allows only includePaths option alone. 根据这个链接https://github.com/angular/angular-cli/issues/1791它只允许includePaths选项。

Hope this helps !!! 希望这可以帮助 !!!

If you use css-loader, You can enable module feature. 如果使用css-loader,则可以启用模块功能。 Enabling that will gives you flexibility to import css just like requiring javascript object. 启用它将为您提供导入css的灵活性,就像需要javascript对象一样。 I used for react, You can do the same for angular guess. 我用过反应,你可以做同样的角度猜测。 It is very cool feature you should check this out. 这是非常酷的功能你应该检查出来。

//css 
.app p {
  color: green;
}

//JS
import styles from './app.css';

     <div className={styles.app}>
        <p>{ this.state.count }</p>
        <button onClick={() => this.increment()}>Increment</button>
      </div>

https://github.com/webpack-contrib/css-loader https://javascriptplayground.com/css-modules-webpack-react/ https://github.com/webpack-contrib/css-loader https://javascriptplayground.com/css-modules-webpack-react/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM