简体   繁体   中英

Compile multiple cljs-files to independent js-files

Edit: In case someone tries to build independent cljs/js-files for one project: It works exactly the way described below. You just have to ensure the cljs-directories contain just the required files - it was my fault to leave unintentionally a copy of another (not used) cljs-file in one directory; although not referenced, this will be compiled into wanted file.

I use cljsbuild with multiple builds to generate two different cljs/js-files on same page. There are no dependencies between these files and they use different namespaces. Compiling in advanced-mode builds two js-files, where one of the js-file includes the whole other - so that one files grows unnecessary.

Is there a way to generate two completely independent js-files without setting up two different projects?

Part of my project.clj:

:cljsbuild {:builds {:app1 {:source-paths ["src/cljs-app1"]
                          :compiler {:output-to     "resources/public/js/app1.js"
                                     :output-dir    "resources/public/js/out-app1"
                                     :asset-path   "/js/out-app1"
                                     :optimizations :none
                                     :pretty-print  true}}
                   :app2 {:source-paths ["src/cljs-app2"]
                          :compiler {:output-to     "resources/public/js/app2.js"
                                     :output-dir    "resources/public/js/out-app2"
                                     :asset-path   "/js/out-app2"
                                     :optimizations :none
                                     :pretty-print  true}}}}

:profiles {:dev {:cljsbuild {:builds {:app1 {:compiler {:source-map true}}
                                  :app2 {:compiler {:source-map true}}}}}

         :uberjar {:hooks [leiningen.cljsbuild minify-assets.plugin/hooks]
                   :env {:production true}
                   :aot :all
                   :omit-source true
                   :cljsbuild {:jar true
                               :builds {:app1 {:compiler
                                              {:optimizations :advanced
                                               :pretty-print false}}
                                        :app2 {:compiler
                                               {:optimizations :advanced
                                                :pretty-print false}}}}}
       :production {:cljsbuild {}}
       }

找到了可能对https://github.com/thheller/shadow-build有用的东西

Currently the combined list of source paths is used when compiling each of the builds, which may lead to surprising inclusions/leaks in the resulting js files. A work-around is to run cljsbuild separately for each build:

lein cljsbuild once app1
lein cljsbuild once app2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM