JMDE
JMDE

Reputation: 1115

Use Node.js as standalone LESS-compiler in project?

I've been trying to incorporate the lessc compiler in a large project that has the basic setup from Bootstrap and it only results in various compileerrors (for which there are tickets for everyone with different solutions).

Not one solution give me what I want, which is a way to compile the less-pile through the command line.

I compile various other assets through node.js and hoped to do the same thing with the less, but every googlepage I find on the subject is Node.js+Express which is not what I want. I want a standalone compiler. (Idea: require.js r.js-file)

I found Node-less but it hasnt seen a update in 2 years and as such isnt ideal.

So. Question: Is there a commandline way to compile less-files with node.js? Ideal impl:

node compiler.js build.js

where build.js is a file with path to bootstrap.less and everything else needed.

Example of a r.js config file:

({
    baseURL : "../assets",
    mainConfigFile : "../assets/main.js",
    name : "../assets/main",
    out : "../assets/main.optmin.js",
    optimize : "uglify"
})

Upvotes: 6

Views: 4217

Answers (1)

JMDE
JMDE

Reputation: 1115

Here is how to use node and less to output to a file:

node path/to/less/bin/lessc -x -O2 path/to/assets/main.less > path/to/output.css

-x : compress

-O2 : optimization mode

which creates output.css from main.less. Might be simple but I havn't found this ANYWHERE on the net. That line can be incorporated in a deployment-script.

Upvotes: 11

Related Questions