How to get the Ruby ‘lessc -w’ option under Node for LessCss
If you’re one of those early adopters of LessCss, then you probably know by now that development of the original Ruby version has been abandoned in favor of a version that runs under Node.js. I’m a big fan of LessCss; both the nested definitions and parametric definitions make my life a whole lot easier.
I installed the latest version today and noticed that it’s missing a feature I really liked in the Ruby edition: the “watch” feature. This would allow you to edit your LessCss source document, and would automagically re-run the compiler to produce valid CSS. You wouldn’t have to run it by hand to tweak your document. The Node.js version of LessCss doesn’t have this feature.
It’s possible to get the same effect, however, if you’re running a system that uses inotify. If you have inotify in your kernel, install inotify tools, and you’ll have the program inotifywait, which is a useful tool for the command line that waits until a file changes, and then allows your script to proceed.
In bash, the code is:
while true; do inotifywait style.less ; lessc style.less style.css ; done
That’s it. Now, every time you save your LessCss file, the css equivalent will be automatically generated.