Webpack scss-vars-to-js plugin
How it works
It parses *.scss files with variable definitions to JS module and allows you to use it from JS code.
Usage
const ScssVarsPlugin = ; const webpackConfig = //... plugins: //... source: 'src/styles/vars.scss' target: 'src/scripts/vars.js' ;
Plugin is capable of parsing file with simply structured varialbes in SCSS format. It also supports basic operators on primitive values like +, -, *, /.
; //i.e. ;; ;;;
The SCSS file source above would be parsed to JS file as:
const variableName = 'variableValue';const colorBlack = 'black';const colorOther = '#fafafa';const sizeX = '12px';const someValue = 10;const otherValue = someValue + 1;
Options
- source: source files to be parsed - it can be string or array of multiple path strings
- target: generated *.js file will be saved here
Additionally each line can be annotated with a comment in the following way:
; //skip-js-export
Available comments are:
- //skip-js-export: Skips this line while parsing
- //js-raw: Force export as a string (it won't be treated as variables)
- //js-evaluate: Force evaluation as variables