Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 303
thv Avatar asked Feb 23 '12 21:02

thv


People also ask

Does less need to be compiled?

Using Less. js in the browser is the easiest way to get started and convenient for developing with Less, but in production, when performance and reliability is important, we recommend pre-compiling using Node.

What is the purpose of less js?

Less (which stands for Leaner Style Sheets) is a backwards-compatible language extension for CSS. This is the official documentation for Less, the language and Less. js, the JavaScript tool that converts your Less styles to CSS styles. Because Less looks just like CSS, learning it is a breeze.

How can I download less js?

The client-side compiler less. js can be downloaded from http://lesscss.org/. You can use less. js in the browser, which is a great tool to get you started with Less, although it should only be used for development.


2 Answers

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/

like image 140
Lebovski Avatar answered Oct 11 '22 09:10

Lebovski


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.

like image 35
The Nobility Avatar answered Oct 11 '22 09:10

The Nobility