Load global SASS vars from JS/JSON files or from Webpack config.
npm install @epegzz/sass-vars-loader --save-dev
Simply pass the SASS vars as plain JS object to the sassVars
config property:
// webpack.js
loader: ExtractTextPlugin.extract('style', 'css!sass!@epegzz/sass-vars-loader')
sassVars: {
vars: {
breakpoints: {
small: '300px',
medium: '600px'
}
colors: {
error: 'red';
}
}
}
Pass filenames as array to the sassVars
config object:
// webpack.js
loader: ExtractTextPlugin.extract('style', 'css!sass!@epegzz/sass-vars-loader')
sassVars: {
files: [
path.resolve(__dirname, '/path/to/breakpoints.js'), // JS
path.resolve(__dirname, '/path/to/colors.json'), // JSON
]
}
With breakpoints.js
:
const breakpoints = {
small: '300px',
medium: '600px',
}
module.exports = { breakpoints };
And colors.json
:
{
"colors": {
"error": "red"
}
}
This will result in the following SASS vars being available in all SASS files:
$breakpoints: (
small: 300px,
medium: 600px,
);
$colors: (
error: red,
);
SASS var generator shamelessly copied from Kasu/jsonToSassVars.js