space borg space borg - 1 year ago 142
Less Question

How to compile multiple files at once from command line?

I'm beginning with lesscss and I don't want to use some GUI tools but command line only.

My structure is the following


--- less

--- css

I would like to compile all less files to the css folder. How to achieve this ?

Thanks in advance!

Answer Source

By default the command line compiler (lessc) which can be installed by running npm install less compiles a single Less file into a single.css file.

Depending of the structure of your project and Less files you should choose how to compile all your Less files.

When you want to compile each Less file into a CSS file you can write some command line scripting that iterate over your files and compile each by invoking the lessc compiler. Probably you should better consider to use a task runner for instance gulp-less or grunt-contribe-less.

In most situations the Less code in the different files is related, one file defined variable and mixins used in other files and so on. For that situation you can create a single project.less file which imports the other files:


@import "variable.less";
@import "theme.less";

Now you will have to compile only the project.less. You can do this by running lessc project.less project.css. The preceding command compiles your Less code into a single CSS again.

To answer you question only theoretical, when your Less files do not depend on each other and your only want to compile them all into a single CSS file, you can run (on linux/unix):

paste -s less/*.less | lessc - > css/project.css

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download