I have looked around and I\'ve seen one solution where in your html, you\'d have a tag dedicated to pass sass variables to javascript. I\'m talking about the second answer f
If you are using GULP
or GRUNT
(I hope you are using the first one)
gulp
:Define the colors in the gulpfile, or in another file and then import it to your gulpfile, and then you can dynamically build both the SCSS
variables and the javascript like so:
...
$colors : ([COLORS])
...
var appColors = {[COLORS]};
var gulp = require('gulp'),
gutil = require('gulp-util'),
replace = require('gulp-replace');
var appColors = {
"red" : "#d63737",
"green" : "#69c962"
};
gulp.task('scssVars', ()=>{
var colorsString = JSON.stringify(appColors);
colorsString = colorsString.slice(2,colorsString.length - 2);
return gulp.src('css/variables_template.scss')
.pipe(replace(/[COLORS]/g, colorsString ))
.pipe(rename('variables.scss'))
.pipe(gulp.dest('/'))
});
// do more of less the same for your app.js, only without renaming, if possible
Similar NPM gulp packages for SCSS variables: