更少:以编程方式使用时(通过API)传递选项 [英] Less: Passing option when using programmatically (via API)
问题描述
在命令行上使用lessc
时,我可以通过选项--modify-var="my-var=my-val"
.
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)
?
我希望以某种方式可以像{modifyVar:'my-var=my-val'}
这样在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.
感谢您的帮助.
推荐答案
不幸的是,API文档中没有描述这些选项.了解它们的最简单方法是研究 https:的来源: //github.com/less/less.js/blob/master/bin/lessc .
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.
选项和ModifyVars选项都应该是一个对象.对于modifyVars
选项,每个变量应该是对象的键.键可能但不必以@
开头.
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 @
.
示例:
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);
});
以上内容应输出如下:
t {
color1: blue;
color2: darkblue;
}
这篇关于更少:以编程方式使用时(通过API)传递选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!