2014-05-04 62 views
4

project.clj:cljsbuild部分有很多重複的:如何避免cljsbuild項目中的重複?

:cljsbuild { 
    :builds {:dev {:source-paths ["src-cljs"] 
       :compiler {:output-dir "resources/public/js" 
          :output-to "resources/public/js/main.js" 
          :optimizations :whitespace 
          :pretty-print true 
          :source-map "resources/public/js/main.map" 
          :language-in :ecmascript5 
          :foreign-libs [{:file "third-party/mutation-summary/mutation-summary.js" 
              :provides ["MutationSummary"]}]}} 
      :production {:source-paths ["src-cljs"] 
         :compiler {:output-to "resources/public/js/main-min.js" 
            :optimizations :advanced 
            :pretty-print false 
            :language-in :ecmascript5 
            :foreign-libs [{:file "third-party/mutation-summary/mutation-summary.js" 
                :provides ["MutationSummary"]}]}} 
      :test {:source-paths ["src-cljs" "test-cljs"] 
        :compiler {:output-to "resources/private/js/unit-test.js" 
          :optimizations :whitespace 
          :pretty-print true 
          :language-in :ecmascript5 
          :preamble ["react/react.min.js"] 
          :externs ["react/externs/react.js"] 
          :foreign-libs [{:file "third-party/mutation-summary/mutation-summary.js" 
              :provides ["MutationSummary"]}]}}} 
    :test-commands {"unit-tests" ["slimerjs" :runner 
           "resources/private/js/unit-test.js"]}} 

我敢肯定,它必須能夠使用配置文件刪除此重複,但我Leiningen福缺乏。

回答

1

一個不那麼漂亮,但可行的解決辦法是增加你的defproject保存您正在重用的標準參數,例如高於defdefn:(不spellchecked也沒有發揮作用的例子)

(def defaults 
    "Returns default compiler options" 
    {:language-in :ecmascript5 
    :foreign-libs [{:file "third-party/mutation-summary/mutation-summary.js" 
        :provides ["MutationSummary"]}]}) 

而且然後到merge,該圖與自定義值映射:

:builds {:dev {:source-paths ["src-cljs"] 
       :compiler  (merge defaults {:pretty-print true})