Skip to content

Advanced Compilation

David Nolen edited this page Jun 16, 2015 · 11 revisions

If you are targeting traditional JavaScript clients (web browsers) it's important to think about advanced compilation from the very beginning. Otherwise you will inevitably find yourself going through issues that could have been easily avoided with a little bit of up front preparation.

Avoid Foreign Libraries

It's best to simply avoid foreign libraries if a solution exists either in Google Closure Library or in an ClojureScript library. Foreign libraries must supply externs for advanced compilation to work consistently.

Of course, in some cases foreign libraries cannot be avoided.

Using Foreign Libraries

If you must a foreign library use a curated one like those provided by CLJSJS. These come packaged with externs so that you do not have to supply them yourself.

Occasionally you may find yourself needing a foreign library which has not been prepackaged.

Providing externs

When working with a foreign library which does not supply externs take the time to write an externs file for the API you intend to use. Externs file are surprisingly simple to provide. For example if the foreign library has some property Foo.bar that you wish to access your externs file should have the following entry:

Foo.bar;

If the foreign library has some method Foo.baz that you wish to invoke your externs file should have the following entry:

Foo.baz = function() {};
Clone this wiki locally