Skip to content
David Nolen edited this page Feb 17, 2015 · 136 revisions

Here is the list of compiler options that can be passed to the ClojureScript compiler.

Common Options

Less Common Options

Common Options

:output-to

The path to the JavaScript file that will be output.

:output-to "resources/public/js/main.js"

:output-dir

Sets the output directory for temporary files used during compilation. Defaults to "out".

:output-dir "resources/public/js/out"

:optimizations

The optimization level. May be :none, :whitespace, :simple, or :advanced. :none is the recommended setting for development, while :advanced is the recommended setting for production, unless something prevents it (incompatible external library, bug, etc.).

When the :main option is not used, :none requires manual code loading and hence a separate HTML from the other options.

Defaults to :simple.

:optimizations :none

:main

Specify an entry point namespace. When combined with optimizations :none will cause the compiler to emit a single JavaScript file that will import goog/base.js, the JavaScript file for the namespace, and emit the required goog.require statement. This permits leaving HTML markup identical between dev and production.

:main "foo.bar"

Also see :asset-path.

:asset-path

When using :main it is often necessary to control where the entry point script attempts to load scripts from due to the configuration of the web server.

:asset-path "assets/js"

:source-map

See https://github.com/clojure/clojurescript/wiki/Source-maps. Under optimizations :none the valid values are true and false. Under all other optimization settings must specify a path to where the source map will be written.

Under :none:

:source-map true

Otherwise:

:source-map "path/to/source/map.js.map"

:verbose

Emit details and measurements from compiler activity.

:verbose true

:pretty-print

Determines whether the JavaScript output will be tabulated in a human-readable manner. Defaults to true.

:pretty-print true

:target

If targeting nodejs add this line. Takes no other options at the moment. The default (no :target specified) implies browsers are being targeted.

:target :nodejs

:foreign-libs

Adds dependencies on foreign libraries. Be sure that the url returns a HTTP Code 200

Defaults to the empty vector []

:foreign-libs [{ :file "http://example.com/remote.js"
                 :provides  ["my.example"]}]

:externs

Configure externs files for external libraries.

For this option, and those below, you can find a very good explanation at: http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html

Defaults to the empty vector [].

:externs ["jquery-externs.js"]

:modules

A new experimental option for emitting Google Closure Modules. Closure Modules supports splitting up an optimized build into N different modules. If :modules is supplied it replaces the single :output-to. A module needs a name, an individual :output-to file path, :entries a set of namespaces, and :depends-on a set of modules on which the module depends. An example follows:

{:optimizations :advanced
 :output-dir "resources/assets/js"
 :modules {
   :common 
     {:output-to "resources/assets/js/common.js"  
      :entries '#{com.foo.common}}
   :landing 
     {:output-to "resources/assets/js/landing.js" 
      :entries '#{com.foo.landing}
      :depends-on #{:common}}
   :editor 
     {:output-to "resources/assets/js/editor.js"
      :entries '#{com.foo.editor}
      :depends-on #{:common}}}}

Any namespaces not in an :entries set will be moved into the default module :cljs-base. However due to cross module motion, Google Closure will move functions and methods into the modules where they are actually used. This process is somewhat conservative so if you know that you want to keep some code together do this via :entries.

:modules fully supports :foreign-libs. :foreign-libs are always put into dependency order before any Google Closure compiled source.

Source map support for :module is still a work in progress.

Less Common Options

:source-map-path

Set the path to source files references in source maps to avoid further web server configuration.

:source-map-path "assets/js"

:source-map-timestamp

Add cache busting timestamps to source map urls. This is helpful for keeping source maps up to date when live reloading code.

:source-map-timestamp true

:cache-analysis

Experimental. Cache compiler analysis to disk. This enables faster cold build and REPL start up times.

:cache-analysis true

:recompile-dependents

For correctness the ClojureScript compiler now always recompiles dependent namespaces when a parent namespace changes. This prevents corrupted builds and swallowed warnings. However this can impact compile times depending on the structure of the application. This option defaults to true.

:recompile-dependents false

:static-fns

Employs static dispatch to specific function arities in emitted JavaScript, as opposed to making use of the call construct. Defaults to false except under advanced optimizations. Useful to have set to false at REPL development to facilitate function redefinition, and useful to set to true for release for performance.

This setting does not apply to the standard library, which is always compiled with :static-fns implicitly set to true.

:static-fns true

:warnings

This flag will turn on/off compiler warnings for references to undeclared vars, wrong function call arities, etc. Can be a boolean for enabling/disabling common warnings, or a map of specific warning keys with associated booleans. Defaults to true.

:warnings true
;; OR
:warnings {:fn-deprecated false} ;; suppress this warning

The following warnings are supported:

  • :preamble-missing, missing preamble
  • :undeclared-var, undeclared var
  • :undeclared-ns, var references non-existent namespace
  • :undeclared-ns-form, namespace reference in ns form that does not exist
  • :redef, var redefinition
  • :dynamic, dynamic binding of non-dynamic var
  • :fn-var, var previously bound to fn changed to different type
  • :fn-arity, invalid invoke arity
  • :fn-deprecated, deprecated function usage
  • :protocol-deprecated, deprecated protocol usage
  • :undeclared-protocol-symbol, undeclared protocol referred
  • :invalid-protocol-symbol, invalid protocol symbol
  • :multiple-variadic-overloads, multiple variadic arities
  • :variadic-max-arity, arity greater than variadic arity
  • :overload-arity, duplicate arities
  • :extending-base-js-type, JavaScript base type extension
  • :invoke-ctor, type constructor invoked as function
  • :invalid-arithmetic, invalid arithmetic
  • :protocol-invalid-method, protocol method does not match declaration
  • :protocol-duped-method, duplicate protocol method implementation
  • :protocol-multiple-impls, protocol implemented multiple times

:elide-asserts

This flag will cause all (assert x ) calls to be removed during compilation, including implicit asserts associated with :pre and :post conditions. Useful for production. Default is always false even in advanced compilation. Does NOT specify goog.asserts.ENABLE_ASSERTS, which is different and used by the Closure library.

Note that it is currently not possible to dynamically set *assert* to false at runtime; this compiler flag must explicitly be used to effect the elision.

:elide-asserts true

:pseudo-names

With :advanced mode optimizations, determines whether readable names are emitted. This can be useful when debugging issues in the optimized JavaScript and can aid in finding missing externs. Defaults to false.

:pseudo-names true

:print-input-delimiter

Determines whether comments will be output in the JavaScript that can be used to determine the original source of the compiled code.

Defaults to false.

:print-input-delimiter false

:output-wrapper

Wrap the JavaScript output in (function(){...};)() to avoid clobbering globals. Defaults to true when using advanced compilation, false otherwise.

:output-wrapper false

:libs

Adds dependencies on external libraries. Note that files in these directories will be watched and a rebuild will occur if they are modified.

Defaults to the empty vector []

:libs ["closure/library/third_party/closure"]

:preamble

Prepends the contents of the given files to each output file. Only valid with optimizations other than :none.

Defaults to the empty vector []

:preamble ["license.js"]

:compiler-stats

Report basic timing measurements on compiler activity.

Defaults to false.

:compiler-stats true

:language-in and :language-out

Configure the input and output languages for the closure library. May be :ecmascript3, ecmascript5, or ecmascript5-strict.

Defaults to :ecmascript3

:language-in  :ecmascript3
:language-out :ecmascript3

:closure-warnings

Configure warnings generated by the Closure compiler. A map from Closure warning to configuration value, only :error, :warning and :off are supported.

:closure-warnings {:externs-validation :off}

The following Closure warning options are exposed to ClojureScript:

:access-controls
:ambiguous-function-decl
:debugger-statement-present
:check-regexp
:check-types
:check-useless-code
:check-variables
:const
:constant-property
:deprecated
:duplicate-message
:es5-strict
:externs-validation
:fileoverview-jsdoc
:global-this
:internet-explorer-checks
:invalid-casts
:missing-properties
:non-standard-jsdoc
:strict-module-dep-check
:tweaks
:undefined-names
:undefined-variables
:unknown-defines
:visiblity

See the Closure Compiler Warning wiki for detailed descriptions.

:closure-defines

Set the values of closure libraries variables annotated with @define. A common usage is setting goog.DEBUG to false.

:closure-defines {:goog.DEBUG false}

:closure-extra-annotations

Define extra JSDoc annotations that a closure library might use so that they don't trigger compiler warnings.

:closure-extra-annotations #{"api"}
Clone this wiki locally