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.

Answers:

Answer

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

Answer

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.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.