Compiler Options


:anon-fn-naming-policy

:asset-path

A path to :output-dir relative to your web server's root, if not already specified as such. Only required when :optimizations is :none and :main is set, because the generated :output-to file will then need to load other parts of the build at runtime.

:output-to "resources/public/main.js"
:output-dir "resources/public/js/compiled/out"
:asset-path "js/compiled/out" ;; <--- relative URL of output-dir

:browser-repl

:cache-analysis

Cache compiler analysis to disk to enable faster cold build and REPL startup times. Defaults to true in REPL and when :optimizations is disabled. Each CLJS file is cached to :output-dir with analysis formatted by :cache-analysis-format.

  • foo.cljs - copied source
  • foo.cljs.cache.json - analysis in transit format, or
  • foo.cljs.cache.edn - analysis in edn format
:cache-analysis true

:cache-analysis-format

Set the output format of the analysis cache if :cache-analysis is enabled. Defaults to transit json.

                                 ;; for foo.cljs
:cache-analysis-format :transit  ;; <-- foo.cljs.cache.json (default)
:cache-analysis-format :edn      ;; <-- foo.cljs.cache.edn

:closure-defines

:closure-extra-annotations

:closure-generate-exports

:closure-warnings

Control specific warnings generated by the Closure compiler. Each warning must map to either :error, :warning, or :off.

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

:compiler-stats

:dump-core

:elide-asserts

Remove all assert calls during compilation, including :pre and :post condition checks for functions. Useful for production. Defaults to false, even in advanced mode.

:elide-asserts true

:emit-constants

:externs

Files declaring JavaScript symbols that should not be munged under advanced :optimizations.

:externs ["react-externs.js"
          "jquery-externs.js"]

:foreign-libs

Allows you to include and convert JavaScript libraries that are not proper Google Closure namespaces—if they are, use :libs instead. For an easier way to include libraries from npm use :npm-deps.

:foreign-libs
[{:file "local/file.js"         ;; file path or URL
  :provides ["my.example"]      ;; assign a fake namespace

  ;; optional keys
  :file-min "local/file.min.js" ;; used for :advanced optimizations
  :module-type ...              ;; :commonjs, :amd, or :es6
  :requires ["foo.bar"]         ;; inferred if :module-type supplied
  :preprocess ...}]             ;; custom preprocessor (e.g. JSX)


:infer-externs

A helpful facility for generating :externs whenever a . form is used on a type-hinted symbol ^js/Foo.Bar x. Enable *warn-on-infer* to be warned of failed inferences. Successful inferences are written to inferred_externs.js in :output-dir.

:infer-externs true

:language-in

:language-out

:libs

Paths to JavaScript libraries that you wish to include in the build. Libs must be proper Google Closure namespaces, else use :foreign-libs or :npm-deps.

:libs ["src/js"                      ;; <-- all files in directory
       "src/org/example/example.js"] ;; <-- single file

:main

Specifies an entry point namespace. Behavior depends on :optimizations:

  • :simple,:advanced - only namespaces reachable from main are built
  • :none - all namespaces are built, but the :output-to file will be generated such that main is executed for the appropriate :target (browser or Node).
:main "foo.bar"

:modules

Employ code-splitting to replace the usual :output-to file with separate logical modules. Every namespace is assigned to exactly one logical module. Code-motion will enable code to be pulled across module boundaries when possible, but this is avoided if the compiler knows it will already be included on the page:

  • :output-to - output file of a module
  • :entries - namespaces to include (modules must have no entries in common)
  • :depends-on - modules expected to be included on the page beforehand
:modules
{:foo {:output-to "js/foo.js" :entries #{"my.foo"}}
 :bar {:output-to "js/bar.js" :entries #{"my.bar"} :depends-on #{:foo}}
 :baz {:output-to "js/baz.js" :entries #{"my.baz"} :depends-on #{:bar}}

 :cljs-base ;; <-- leftover namespaces are placed here for you
 {:output-to "js/cljs_base.js"}} ;; <-- specify to change base output

:npm-deps

Include libraries from npm. This experimental feature downloads the dependencies from npm and generates a :foreign-libs entry for each.

:npm-deps {:react "15.4.2"
           :lodash "4.17.4"}

:optimizations

The compiler will produce JS based on the optimization level:

  • :none - multiple unminified files (fastest for development).
  • :whitespace - single file w/ comments and whitespace removed
  • :simple - single file w/ whitespace optimizations + minified local var names
  • :advanced - single file w/ aggressive renaming, dead code removal, and inlining
:optimizations :none     ;; <-- recommended for development
:optimizations :advanced ;; <-- recommended for production
:optimizations :simple   ;; <-- recommended for Node

:optimize-constants

:output-dir

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

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

:output-to

The path to the JavaScript file that will be output.

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

:output-wrapper

:parallel-build


:preloads

A list of namespaces to load before :main, allowing you to preload extra code for specific builds. For example, a development build can use it to setup logging or connecting REPLs. Only applies when :optimizations is :none.

:preloads '[foo.dev]

:pretty-print

Determines if the JavaScript output will be formatted to be human-readable. Only applies if :optimizations are enabled. Defaults to false.

:pretty-print true


:pseudo-names

Allows you to retain var names similar to their original when compiling advanced :optimizations. Enable this along with :pretty-print if you wish to read the advanced output for debugging purposes.

:pseudo-names true

:recompile-dependents

For correctness, this defaults to true in order to recompile 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.

:recompile-dependents false

:source-map

To help debugging at runtime, creates a standard source map JSON file used by Node and browsers to map compiled JS lines to their original CLJS files. Use a string path if there is a single output file expected, otherwise use true to auto-assign source map filenames.

:source-map "out/main.js.map"
:source-map true ;; <-- use if `:optimizations :none`, or any `:modules`

:source-map-asset-path

A compiled JS file can contain a sourceMappingURL comment, which cljs uses to locate the :source-map JSON file. You can prepend this location with a custom path if required by your web server configuration.

:source-map-asset-path "..."  ;; <-- custom server path of source map metadata

:source-map-path

Source maps associate compiled JS lines to their original CLJS files. Use this option if you configured your web server to host these original CLJS files at a custom path. If present, it is prepended to all sources inside the :source-map file.

:source-map-path "..."  ;; <-- custom server path of original CLJS files

: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

:static-fns

Controls how multi-arity function calls are generated. A "static" call means the dispatch to the appropriate arity is handled at compile time (better performance), whereas a "dynamic" call means the dispatch is handled at run time (allows safer redefinition in REPL). Static is enabled by default in advanced :optimizations.

:static-fns true

:target

Determines the target environment the compiled code is expected to run on. Use :nodejs for Node.js. If no target is specified, the browser environment is assumed.

:target :nodejs  ;; <-- use when targeting Node.js

:ups-externs

:ups-foreign-libs


:use-only-custom-externs

:verbose

Show the steps the compiler is taking to create the build.

:verbose true

:warning-handlers

:warnings

Enable all or specific compiler warnings. See full details for all warning options. Defaults to true.

:warnings true                  ;; enable all (default)
:warnings {:fn-deprecated true} ;; enable specific warnings

:watch-error-fn