Gathering detailed insights and metrics for node-sass-json-importer
Gathering detailed insights and metrics for node-sass-json-importer
Gathering detailed insights and metrics for node-sass-json-importer
Gathering detailed insights and metrics for node-sass-json-importer
node-sass-magic-importer
Custom node-sass importer for selector specific imports, node importing, module importing, globbing support and importing files only once
node-sass-glob-importer
Custom importer for node-sass which makes it possible to use glob syntax in Sass import statements
node-sass-tilde-importer
A node-sass custom importer which turns ~ into absolute paths to the nearest parent node_modules directory.
node-sass-package-importer
Custom importer for node-sass to import packages from the `node_modules` directory
npm install node-sass-json-importer
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
163 Stars
145 Commits
55 Forks
18 Watching
2 Branches
19 Contributors
Updated on 25 Nov 2024
Minified
Minified + Gzipped
JavaScript (96.19%)
CSS (3.81%)
Cumulative downloads
Total Downloads
Last day
-3.4%
4,777
Compared to previous day
Last week
18.7%
27,374
Compared to previous week
Last month
26.3%
109,495
Compared to previous month
Last year
-38.7%
1,279,482
Compared to previous year
1
JSON importer for node-sass. Allows @import
ing .json
or .json5
files in Sass files parsed by node-sass
.
This module hooks into node-sass's importer api.
1var sass = require('node-sass'); 2var jsonImporter = require('node-sass-json-importer'); 3 4// Example 1 5sass.render({ 6 file: scss_filename, 7 importer: jsonImporter(), 8 [, options..] 9}, function(err, result) { /*...*/ }); 10 11// Example 2 12var result = sass.renderSync({ 13 data: scss_content 14 importer: [jsonImporter(), someOtherImporter] 15 [, options..] 16});
To run this using node-sass CLI, point --importer
to your installed json importer, for example:
1./node_modules/.bin/node-sass --importer node_modules/node-sass-json-importer/dist/cli.js --recursive ./src --output ./dist
1import jsonImporter from 'node-sass-json-importer'; 2 3// Webpack config 4export default { 5 module: { 6 loaders: [{ 7 test: /\.scss$/, 8 loaders: ["style", "css", "sass"] 9 }], 10 }, 11 // Apply the JSON importer via sass-loader's options. 12 sassLoader: { 13 importer: jsonImporter() 14 } 15};
1import jsonImporter from 'node-sass-json-importer'; 2 3// Webpack config 4export default { 5 module: { 6 rules: [ 7 { 8 test: /\.scss$/, 9 use: [ 10 'style-loader', 11 { 12 loader: 'css-loader', 13 options: { 14 importLoaders: 1 15 }, 16 }, 17 { 18 loader: 'sass-loader', 19 // Apply the JSON importer via sass-loader's options. 20 options: { 21 importer: jsonImporter(), 22 }, 23 }, 24 }, 25 ], 26 ], 27 }, 28};
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 unquoted, 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:
1{ 2 "description": "A sentence with spaces." 3}
1{ 2 "description": "'A sentence with spaces.'" 3}
See discussion here for more:
https://github.com/Updater/node-sass-json-importer/pull/5
You can also import *.js Files. This way you can use javascript to compose and export json structure for node-sass-json-importer.
const xl = require('./variables.json')
const md = require('./variables-md.json')
const xs = require('./variables-xs.json')
module.exports = {
xl,
md,
xs,
}
Should you care to resolve paths, say, starting with ~/
relative to project root or some other arbitrary directory, you can do it as follows:
1.sass
:
1@import '~/1.json' 2body 3 margin: $body-margin
json/1.json
:
1{"body-margin": 0}
1var path = require('path'); 2var sass = require('node-sass'); 3var jsonImporter = require('../dist/node-sass-json-importer'); 4 5sass.render({ 6 file: './1.sass', 7 importer: jsonImporter({ 8 resolver: function(dir, url) { 9 return url.startsWith('~/') 10 ? path.resolve(dir, 'json', url.substr(2)) 11 : path.resolve(dir, url); 12 }, 13 }), 14}, function(err, result) { console.log(err || result.css.toString()) });
If you want to convert standard JavaScript caseCase keys into CSS/SCSS compliant kebab-case keys, for example:
variables.json
:
1{ 2 "bgBackgroundColor": 'red' 3}
For usage like this:
style.scss
:
1@import "variables.json"; 2 3div { 4 background: $bg-background-color; 5}
You can pass set the convertCase
option to true as an argument to jsonImporter
like so:
1sass.render({ 2 file: './1.sass', 3 importer: jsonImporter({ 4 convertCase: true, 5 }), 6}, function(err, result) { console.log(err || result.css.toString()) });
This module is based on the sass-json-vars gem, which unfortunately isn't compatible with node-sass
.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 8/12 approved changesets -- score normalized to 6
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
59 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More