Search code examples
clojureleiningen

Run more than one lein task at the same time


I am currently newbie in Leiningen project. I want to compile less to css using lein-less and minify-assets on the fly so I found that I should use lein less auto for the less file and lein minify-assets watch for javascripts and HTML file.

I am using lein-cascade to operate them but it just still on the lein less auto task and not go to lein minify-assets watch

This is my project code

(defproject indecorlein "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.8.0"]]
  :plugins [[lein-asset-minifier "0.4.3"]
            [lein-less "1.7.5"]
            [lein-cascade "0.1.2"]]

  :min-lein-version "2.5.0"

  :cascade {
            "lessc" [["less" "auto"]]
            "min" [["minify-assets" "watch"]]
            "amp" ["lessc" "min"]
            }

  :less {:source-paths ["dev/resources/less"]
         :target-path "dev/resources/css"}

  :minify-assets [
                  [:html {:source "dev/resources/html" :target "dev/minified/html"}]
                  [:css {:source "dev/resources/css" :target "dev/minified/css/styles.min.css"}]
                  [:js {:source ["dev/res/js"] :target "dev/minified/js/amp.min.js"}]])

Maybe there's a solution about this or me just run the tasks on separate terminal tabs.


Solution

  • You can use lein-pdo plugin. Add it into your plugins and define an alias:

      :plugins [...
                [lein-pdo "0.1.1"]]
    
      :aliases {"watch" ["pdo" ["less" "auto"]
                               ["minify-assets" "watch"]]}
    

    Then you can run lein watch which will run both tasks at the same time.