I'm trying to create from one LESS stylesheet, multiple css file, with different names according to a variable value. The LESS modifyVars function seems to run only in a browser enviroment. So, Is possible to use the LESS modifyVars function in nodejs?
1 Answer
You're right, modifyVars is available just in browser.js which is loaded (as the name suggests) just in the browser.
With node, we can achieve the same result by prepending a string containing the variables we wish to modify. Here a very short example:
var less = require('less');
var CSS = '.class { color: @color };';
['red', 'blue', 'yellow'].forEach(function(color, index){
  var settings = '@color: ' + color + ';';
  less.render(settings + CSS, function (e, css) {
    console.log('Script ' + index + ':')
    console.log(css);
    console.log('----')
  });
});
This should give you the same results as modifyVars.
1 Comment
geedmo
 This is a similar behavior but not the same (e.g.) It won't work with import or if @color was declared somewhere in the code. modifiyVars changes values within a parser enviroment. I can't find a way to get that env with node.