Less: Passing option when using programmatically (via API)

断了今生、忘了曾经 提交于 2019-12-13 13:15:07

问题


When using lesscon 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.


回答1:


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;
}


来源:https://stackoverflow.com/questions/28960681/less-passing-option-when-using-programmatically-via-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!