简体   繁体   English

将多个cljs文件编译为独立的js文件

[英]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. 编辑:如果有人尝试为一个项目构建独立的cljs / js文件:它的工作方式完全如下所述。 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; 您只需要确保cljs目录仅包含所需的文件-我的错是无意间在一个目录中保留了另一个(未使用的)cljs文件的副本; 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. 我将cljsbuild与多个构建一起使用,以在同一页面上生成两个不同的cljs / js文件。 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. 在高级模式下编译会生成两个js文件,其中一个js文件包含整个js文件-因此一个文件不再需要。

Is there a way to generate two completely independent js-files without setting up two different projects? 有没有一种方法可以生成两个完全独立的js文件,而无需设置两个不同的项目?

Part of my project.clj: 我的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. 当前,在编译每个内部版本时会使用源路径的组合列表,这可能会导致结果js文件中出现令人惊讶的包含/泄漏。 A work-around is to run cljsbuild separately for each build: 解决方法是为每个构建分别运行cljsbuild:

lein cljsbuild once app1
lein cljsbuild once app2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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