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

后端 未结 14 609
执念已碎
执念已碎 2020-12-12 22:09

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:

         


        
14条回答
  •  失恋的感觉
    2020-12-12 22:39

    I just made the script on top of @iloveitaly's work:

    #!/bin/bash
    # file name: lesscdir
    
    if [[ -z $1 || -z $2 ]];then
        echo 'both arguments are needed'
        exit
    fi
    
    find $1 -name '*.less' -printf '%P\n' | while read name; do
        FROM=$(echo $1'/'$name)
        TO=$(echo $2'/'$name | sed "s|\.less|\.css|")
        TO_DIRNAME=$(dirname $TO)
        if [ ! -e $TO_DIRNAME ];then
            mkdir -p $TO_DIRNAME
        fi
        echo 'Compiling' $FROM '->' $TO
        lessc $FROM $TO
    done
    

    and then:

    $ chmod +x lesscdir
    $ sudo ln -s $(readlink -f lesscdir) /usr/local/bin/
    

    Although I like python the best and solve most problems with it, it's still very happy to use bash in linux environment.

提交回复
热议问题