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

白昼怎懂夜的黑 提交于 2019-12-07 04:02:43

问题


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"
})

回答1:


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.



来源:https://stackoverflow.com/questions/10961180/use-node-js-as-standalone-less-compiler-in-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!