ClojureScript 开发和生产构建

将如下所示的:cljsbuild 节点添加到 project.clj 文件中。

:cljsbuild {
          :builds {
                   ;;Different target goals should have different names.
                   ;;We have the dev build here
                   :dev {
                        ;;The ClojureScript code should reside in these directories
                         :source-paths ["src-cljs"]
                         :compiler {
                                    ;;This is the target output file
                                    ;;This will include none of the goog code.                                  
                                    :output-to "resources/public/js/main.js"
                                    ;;This stores the compilation files, including goog files.
                                    ;;When using this dev profile, you should add "<script src="/js/goog/base.js>" to your html files.
                                    ;;That will load the goog dependency.
                                    :output-dir "resources/public/js/out"
                                    ;;Having optimizations off is recommended for development
                                    ;;However this means you have to add the goog dependencies yourself (see above)
                                    :optimizations :none
                                    ;;With no optimizations, marking this true, means it adds a source map so you can debug in browser
                                    :source-map true
                                    }
                         }
                   :prod {
                                :source-paths ["src-cljs"]
                                :compiler {
                                           ;;Outputs the javascript file to this path.
                                           :output-to "resources/public/js/main.js"
                                           ;;Advanced optimizations make your code smaller.
                                           ;;They include the goog code in your main file.
                                           ;;No need to add an extra script tag.
                                           :optimizations :advanced
                                           :jar true
                                           }
                                }
                   }
          }

要运行这些构建命令,请使用 lein cljsbuild once。你可以通过添加配置文件名称作为最后一个参数来指定要使用的配置文件,例如使用 dev 参数进行编译的 lein cljsbuild once dev

使用 lein cljsbuild auto 将导致 cljsbuild 自动更新任何已更改的文件。