2
votes

Does cljc / lein / clojurescript work yet?

I was previously using cljx, and was able to compile the same project with the cljx plugin for lein firing off a cljsbuild task.

Now I'm switching to cljc, I want to compile my cljc files into both compiled Java and into javascript for use in the browser.

Here's my current project.clj file

(defproject com.mysite/myproj "0.3.2-SNAPSHOT"
  :description ""
  :url ""
  :license {:name "Gnu Lesser Public License"
            :url "https://www.gnu.org/licenses/lgpl.html"}    
  :dependencies [[org.clojure/clojure "1.7.0"]]    
  :plugins [[lein-cljsbuild "1.0.3"]
            [lein-localrepo "0.4.0"] ]    
  :source-paths ["cljc" "src" ]    
  :cljsbuild {:builds [{
                        :source-paths ["cljc"  ]
                        :compiler {
                                   :output-to "browser-based/js/main.js"
                                   :optimizations :whitespace
                                   :pretty-print true }
                        } ]}    
  :hooks [leiningen.cljsbuild]
  :aot [myproj.core]
  :main myproj.core)

I don't remember exactly where I copied some of this from, but I assume that the leiningen.cljsbuild hook was what automatically fired off the cljs build process. However after removing the cljx plugin, and moving to cljc, this is successfully compiling the Java version of my program but doesn't seem to be producing any javascript.

1
Can you post your directory tree?Justin Thomas

1 Answers

2
votes

Yes, it works.

Try with:

(defproject com.mysite/myproj "0.3.2-SNAPSHOT"
  :description ""
  :url ""
  :license {:name "Gnu Lesser Public License"
            :url "https://www.gnu.org/licenses/lgpl.html"}    
  :dependencies [[org.clojure/clojure "1.7.0"]
                 [org.clojure/clojurescript "1.7.28"]    
  :plugins [[lein-cljsbuild "1.0.6"]
            [lein-localrepo "0.4.0"]]   
  :source-paths ["cljc" "src"]    
  :cljsbuild {:builds [{
                        :source-paths ["cljc" "src"]
                        :compiler {:output-to "browser-based/js/main.js"
                                   :optimizations :whitespace
                                   :pretty-print true}}]}    
  :hooks [leiningen.cljsbuild])

Then run: lein compile or lein cljsbuild once

Please note that I changed the :source-paths under :cljsbuild to include "src": :source-paths ["cljc" "src"]. Apart from that I added an explicit dependency on clojurescript and bumped cljsbuild version to 1.0.6

By the way, why do you have a separate cljc directory? You can have your cljc, clj & cljs files sharing the same directory structure.