0

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.

1 Answer 1

9

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.