emezeske/lein-cljsbuild — Issue #21: Support for passing "--define" option to compiler.jar
Author: RafalBabinicz
Created: 2012-01-23 23:17:01+00:00
State: open

for example by specifying in project.clj
:compiler {
:define "goog.userAgent.ASSUME_MOBILE_WEBKIT"
:define "goog.userAgent.product.ASSUME_ANDROID"
}

Resources:
*goog.userAgent global props:* http://closure-library.googlecode.com/svn/docs/closure_goog_useragent_useragent.js.html
*goog.userAgent.product global props:* http://closure-library.googlecode.com/svn/docs/closure_goog_useragent_product.js.html
*"java -jar compiler.jar --help"* for all available options
*Google Closure Definitive Guide at Google Books*: http://books.google.pl/books?id=p7uyWPcVGZsC

**clojurescript/src/clj/cljs/closure.clj: functions "make-options" and "set-options"**

(defn set-options
"TODO: Add any other options that we would like to support."
[opts ^CompilerOptions compiler-options]
(when (contains? opts :pretty-print)
(set! (.prettyPrint compiler-options) (:pretty-print opts)))
(when (contains? opts :print-input-delimiter)
(set! (.printInputDelimiter compiler-options)
(:print-input-delimiter opts))))

(defn make-options
"Create a CompilerOptions object and set options from opts map."
[opts]
(let [level (case (:optimizations opts)
:advanced CompilationLevel/ADVANCED_OPTIMIZATIONS
:whitespace CompilationLevel/WHITESPACE_ONLY
:simple CompilationLevel/SIMPLE_OPTIMIZATIONS)
compiler-options (doto (CompilerOptions.)
(.setCodingConvention (ClosureCodingConvention.)))]
(do (.setOptionsForCompilationLevel level compiler-options)
(set-options opts compiler-options)
compiler-options)))