Trying to add the node-sass-json-importer into an Angular CLI application.
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.
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.
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.
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.
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.
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 !!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With