
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@density/node-sass-json-importer
Advanced tools
Allows importing json in sass files parsed by node-sass.
JSON importer for node-sass. Allows @importing .json files in Sass files parsed by node-sass.
NOTE: This is a fork of Updater/node-sass-json-importer. We've added a transformation of camelcased keys to kabob-cased keys automatically. For example:
{
"fooBar": "baz"
}
is converted to:
$foo-bar: baz;
This module hooks into node-sass's importer api.
var sass = require('node-sass');
var jsonImporter = require('node-sass-json-importer');
// Example 1
sass.render({
file: scss_filename,
importer: jsonImporter,
[, options..]
}, function(err, result) { /*...*/ });
// Example 2
var result = sass.renderSync({
data: scss_content
importer: [jsonImporter, someOtherImporter]
[, options..]
});
To run this using node-sass CLI, point --importer to your installed json importer, for example:
./node_modules/.bin/node-sass --importer node_modules/node-sass-json-importer/dist/node-sass-json-importer.js --recursive ./src --output ./dist
import jsonImporter from 'node-sass-json-importer';
// Webpack config
export default {
module: {
loaders: [{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
}],
},
// Apply the JSON importer via sass-loader's options.
sassLoader: {
importer: jsonImporter
}
};
import jsonImporter from 'node-sass-json-importer';
// Webpack config
export default {
module: {
rules: [
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1
},
},
{
loader: 'sass-loader',
// Apply the JSON importer via sass-loader's options.
options: {
importer: jsonImporter,
},
},
],
],
},
};
Since JSON doesn't map directly to SASS's data types, a common source of confusion is how to handle strings. While SASS allows strings to be both quoted and unqouted, strings containing spaces, commas and/or other special characters have to be wrapped in quotes. In terms of JSON, this means the string has to be double quoted:
{
"description": "A sentence with spaces."
}
{
"description": "'A sentence with spaces.'"
}
See discussion here for more:
https://github.com/Updater/node-sass-json-importer/pull/5
This module is based on the sass-json-vars gem, which unfortunately isn't compatible with node-sass.
FAQs
Allows importing json in sass files parsed by node-sass.
The npm package @density/node-sass-json-importer receives a total of 4 weekly downloads. As such, @density/node-sass-json-importer popularity was classified as not popular.
We found that @density/node-sass-json-importer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.