How to use less.js with node.js to watch .less files in a folder?

thv picture thv · Feb 23, 2012 · Viewed 17k times · Source

I am looking for a simple guide to setting up server-side watching and compiling .less files in a folder using less.js and node.js. Bryan wrote about it in this post.

Unfortunately, the instructions to Server-side usage on lesscss.org are of a little avail to somebody who is new to node.js.

I have tried command line usage: $ lessc styles.less > styles.css.

I have also tried 'watchr' and 'watch-less' and it all works. However, I am looking for a pure node.js + less.js solution. I am sure there is somebody who will be able to plainly explain how to configure node.js and less.js to watch .less files in a folder. Thanks.

Answer

Lebovski picture Lebovski · Feb 24, 2012

I have created demo project to show how it works. You can find it here https://github.com/corpix/watcherDemo

After clone enter project directory and execute npm install to install less Node.js module. Try running index.js and change .less file into less_files/ directory, modified file will be compiled and placed into css_files/