:closure-defines

compiler optionsince v0.0-2120Edit

Assign goog-define vars with compile-time constants. Vars must be specified as a namespace-qualified symbol, and their values must be a string, number, or a boolean.

:closure-defines {my.core/foo "new-value"}

This will result in the following var being replaced:

(ns my.core)

(goog-define foo "default-value") ;; <-- replaced with "new-value"
(println foo) ;; <-- prints "new-value"

Details:

Be aware that a symbol name is interpreted as the original name in ClojureScript, whereas a string name is interpreted as the munged name in JavaScript:

;; Symbol (original name)
:closure-defines {my.core/foo! "..."}

;; String (munged name)
:closure-defines {"my.core.foo_BANG_" "..."}

Also note that:

  • When :optimizations :none, closure-defines have no effect unless :main is specified.
  • When :optimizations :whitespace, closure-defines have no effect.

See Also: