Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I compile a directory full of less css files to css?

Tags:

css

less

I have a directory full of less css files. What is the best way to compile them to normal css? (for deployment)

Id like to run a command as follows:

lessc -r less/ css/ 

where lessc is the less compiler (installed via node package manager)

like image 694
ocoutts Avatar asked Apr 17 '11 03:04

ocoutts


People also ask

How can you compiling less to the CSS?

Pre-compiling LESS into CSS: To compile LESS into CSS, we use the below command in a command prompt. The lessc command lets us precompile our LESS file into a basic CSS file. This helps us in writing modular code using LESS programming and still getting all the benefits of CSS by compiling it into traditional fast CSS.

Does less need to be compiled?

When using the less file, which the browser doesn't understand as is, you need to include a Javascript LESS compiler which reads the less file and translates it to CSS which the browser does understand.


2 Answers

The way to do this is what bootstrap does - have a file which imports all the others and compile that.

@import "variables.less";  @import "mixins.less"; 
like image 115
Damian Avatar answered Sep 22 '22 09:09

Damian


You can use the following bash one-liner to compile and all less files in a directory and its subdirectories into a single css file "combined.css":

$ find less_directory/ -name '*.less' -exec lessc {} \; > combined.css 

Or minified for production:

$ find less_directory/ -name '*.less' -exec lessc -x {} \; > combined.css 
like image 30
Dan Noble Avatar answered Sep 23 '22 09:09

Dan Noble