问题
Using cljsbuild, I can compile all my .cljs files to one file. However, I wish to be able to pick a directory for output and have each .cljs file compile into its own .js file. How can this be specified?
回答1:
You can use 'multiple build configurations': cljsbuild accepts a vector of configurations for :builds
key, each element of which defines rules for compiling separate .js file (more info could be found in lein-cljsbuild README). Simple example:
:cljsbuild
{:builds
[;; Config for first .js file
{:source-paths ["dir-with-cljs-for-first-js"]
:compiler {:output-to "dir-for-js/first.js"}
;; Config for second .js file
{:source-paths ["dir-with-cljs-for-second-js"]
:compiler {:output-to "dir-for-js/second.js"}}]}
回答2:
You're looking for the :output-dir option. My cljsbuild looks like this:
:cljsbuild
{:builds
[{:id "dev"
:source-paths ["src/cljs"]
:compiler {:output-to "resources/public/js/site.js"
:output-dir "resources/public/js/out"
:source-map true :optimizations :none }}
{:id "main"
:source-paths ["src/cljs"]
:compiler {:pretty-print false
:output-to "resources/public/js/site.js"
:source-map "resources/public/js/site.js.map"
:optimizations :advanced}}]}
With this config, and without site.js already compiled/up to date, lein cljsbuild once dev
or lein cljsbuild auto dev
will compile site.js, then see it's dependencies aren't compiled and go compile them, along with their sourcemaps. If site.js is compiled and up to date, cljsbuild will think there's nothing to be done and terminate before generating source maps, etc.
I also highly recommend lein figwheel for cljs development, and remember to enable sourcemaps.
来源:https://stackoverflow.com/questions/15939816/how-to-output-individual-files-to-a-specified-directory-for-cljsbuild