Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClojureScript Leiningen compile to a single .js file?

Can Leiningen be configured in such way that it bundles all compiled JS to a single file? Currently it outputs over a hundred files, which would be very slow in production.

I'm using Chestnut boilerplate, by the way. The documentation says:

Q: I just want to compile ClojureScript to fully optimized JavaScript, so I can use it in a static HTML site.

A: Invoke cljsbuild with the uberjar profile active, like this: lein with-profile -dev,+uberjar cljsbuild once, then look for resources/public/js/app.js.

I've tried it, but the resulting app.js is still just loads the dependencies from other files, it doesn't contain the whole app.

like image 996
Victor Marchuk Avatar asked Oct 30 '22 20:10

Victor Marchuk


2 Answers

As pointed out in the comments: make sure you use one of the following :optimizations:

  • :whitespace
  • :simple
  • :advanced

You can find more information in the ClojureScript wiki: https://github.com/clojure/clojurescript/wiki/Compiler-Options#optimizations

like image 78
Martin Klepsch Avatar answered Nov 02 '22 22:11

Martin Klepsch


It seems like lein with-profile -dev,+uberjar cljsbuild once does generate a single .js bundle. :uberjar profile already has :optimizations :advanced option set in:

:uberjar {:source-paths ["env/prod/clj"]
                       :hooks [leiningen.cljsbuild]
                       :env {:production true}
                       :omit-source true
                       :aot :all
                       :main calc-pack.server
                       :cljsbuild {:builds {:app
                                            {:source-paths ["env/prod/cljs"]
                                             :compiler
                                             {:optimizations :advanced
                                              :pretty-print false}}}}}

Apparently, it wasn't working properly because of errors in my own code.

like image 24
Victor Marchuk Avatar answered Nov 02 '22 23:11

Victor Marchuk