Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrate node-sass-json-importer into an Angular CLI application

Trying to add the node-sass-json-importer into an Angular CLI application.

I was using version 1.0.0-beta.17of 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.

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.

like image 492
subarroca Avatar asked Dec 21 '16 10:12

subarroca


People also ask

How would you use Sass in angular?

In the Angular CLI, all components are self-contained and so are their Sass files. In order to use a variable from within a component's Sass file, you'll need to import the _variables. scss file. One way to do this is to @import with a relative path from the component.

Does angular need node-sass?

If your application uses Angular CDK or Angular Material, you'll need to make sure you've switched from node-sass to the sass npm package. The node-sass package is unmaintained and no longer keeps up with new feature additions to the Sass language.

Does angular compile SCSS?

The Angular CLI can help you styleThe CLI now has an option to provide a inlineStyleLanguage and compiles Sass directly from your Angular components into styling. This is helpful for developers using single file components or who want to add small amounts of styling within their component files.


1 Answers

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');

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,
                    }
                }]
        }

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' ,

as per this link https://github.com/angular/angular-cli/issues/1791 it allows only includePaths option alone.

Hope this helps !!!

like image 71
Ampati Hareesh Avatar answered Oct 11 '22 19:10

Ampati Hareesh