问题
Is there a function in less.js to pass a string of less code and return css code? I'm hoping to make a live less editing environment, so the user could edit the less string and I can recompile it and display the css. I see there is a php solution: http://leafo.net/lessphp/ but would like to stay in js if it's a possibility. Thanks!
回答1:
You can instantiate the less.Parser. Looking at the browser.js source it actually turned out to be quite easy:
var cssString = '@color: #FFFF00; body { color: @color; }';
new(less.Parser)().parse(cssString, function (e, tree) {
var css = tree.toCSS();
alert(css);
});
来源:https://stackoverflow.com/questions/9316385/pass-a-string-of-less-to-less-js-and-receive-css