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

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


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/


Honestly, I have seen a lot of the same threads and answers.

If you are like me and don't want any more code bloat than you already have then just download a LESS app for Win/Mac/Nix and it will auto-compile every time you save your .less files.

I honestly think this would put less of a load on the server because you only need to upload your compiled and minified files at this point.


I wrote something that could be what you are looking for. The script will look for .less files in the watch folder and compile them into the output folder. All you need to do is specify the folder you want to watch and the output folder.

node less-watch-compiler.js FOLDER_TO_WATCH FOLDER_TO_OUTPUT

https://github.com/jonycheung/Dead-Simple-LESS-Watch-Compiler

It skips watching files with names that starts with underscore or a period.

I wrote this for my development process but it should still work on a server. However, you may want to re-consider watching a folder for changes constantly on a live server. It's an expensive operation.