Reputation: 352
I'm beginning with lesscss and I don't want to use some GUI tools but command line only.
My structure is the following
root
--- less
--- css
I would like to compile all less files to the css folder. How to achieve this ?
Thanks in advance!
Upvotes: 1
Views: 3339
Reputation: 1903
You can go through this doc. Though, I'll explain a bit of it.
Install lessc-each
package
$ npm install -g lessc-each
Then, in command line
$ lessc-each ‹dir1› ‹dir2›
Where ‹dir1› is the directory of Less files to compile, and ‹dir2› is the directory for output files. If ‹dir2› does not exist, it will automatically be created. Both directories must be relative to the current path of the command line.
Refer the above given link as there are some restriction also like the file name as file name starting with double-underscore (__) will not be compiled.
Upvotes: 4
Reputation: 1
I found this question, when I looking for solution of similar task and here is my final shell command for compile:
ls PATH_TO_LESS/*.less | xargs -I {} echo "printf 'Start compile file {}' &&" node_modules/less/bin/lessc --clean-css --relative-urls {} "{}# && echo ' - DONE'" | sed 's/\.less#/.css/g' | bash
This command compile all less files from given path to same path with replacing extension "less" => "css".
It's bit longer so I can explain it more if it's necessary.
There is same simplified command without info log output:
ls PATH_TO_LESS/*.less | xargs -I {} echo node_modules/less/bin/lessc --clean-css --relative-urls {} "{}# | sed 's/\.less#/.css/g' | bash
Best on this solution for me is that you can use pure npm as task manager without any other dependency like gulp or grunt. I hope it helps someone.
Upvotes: 0
Reputation: 49044
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:
project.less:
@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
Upvotes: 3