简体   繁体   中英

LESS code to CSS with JS

Is there a way to convert LESS code to CSS with Javascript? Having the LESS code in a javascript variable, I want to compile it, and to get the CSS code into another javascript variable.

EDIT!

I want to convert a LESS code snippet to CSS with JS. User writes LESS code in a textarea and my code has to convert it to CSS real time.

If you are using less.js you can do the following:

var parser = new(less.Parser);

parser.parse(myLessCode, function (err, tree) {
    if (err) { return console.error(err) }
    css = tree.toCSS();
    console.log(css);
});

Checked it in jsfiddle and it works: http://jsfiddle.net/3AHTW/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM