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 自動更新任何已更改的檔案。