0

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 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.