Reputation: 18169
When using lessc
on the commandline, I can pass the option --modify-var="my-var=my-val"
.
How can I pass the same option when I use less programmatically via API with less.render(lessInput, options)
?
I would somehow hope that I can set a property in options
like {modifyVar:'my-var=my-val'}
. But this seems not to work and I didn't find any documentation regarding this use case.
Thanks for any help.
Upvotes: 4
Views: 1004
Reputation: 49054
Unfortunately the options are not described at the API documentation. The easiest way to understanding them, will be by studying the the source of https://github.com/less/less.js/blob/master/bin/lessc.
Both the options and modifyVars option should be an object. For the modifyVars
option each variable should be a key of the object. Keys may but don't have to start with a @
.
Example:
var less = require('less/lib/less-node');
var options = {};
options['modifyVars'] = {'color1' : 'blue', '@color2': 'darkblue'};
less.render('@color1: red; @color2:yellow; t {color1: @color1; color2: @color2;}', options)
.then(function(output) {
// output.css = string of css
// output.map = undefined
console.log(output.css);
});
The above should output as follows:
t {
color1: blue;
color2: darkblue;
}
Upvotes: 5