Mass compile less files into css

Suppose you are using less and want to add the build step that does compile less into css over the whole project.

Here are the steps:

1. Install lessc

2. Install compresser if you need it

Now create following shell scripts and add them into your build process:

3. compiles single less file (change --clean-css options to what you need)

if [ $1 ]; 
    _basename=$(basename $1 .less)
    _dirname=$(dirname $1) 
    echo "Usage: sh <full_path_to_less>"
    echo "Example: sh path/to/styles.less"
echo "Compiling "$1
lessc $1 $_dirname"/"$_basename".css" --clean-css="--s1 --advanced"

4. compiles all less files in project/styles/dir and its descendants. styles.less -> styles.css

find project/styles/dir -name *.less -exec sh {} \;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.