I have done some work to make it easy to use "foreign" libraries in
ClojureScript - by "foreign", I mean libraries that are neither
ClojureScript nor GClosure-aware. (The term "external" is already
overloaded in GClosure, so I tried to avoid that).
All you have to do to include a foreign library is add a :foreign-libs
key to your compiler options. The following code, for example,
includes the excellent Raphael.js library.
(closure/build "src/cljs" {:optimizations :simple
:foreign-libs [{:file "https://
raw.github.com/DmitryBaranovskiy/raphael/master/raphael-min.js"
:provides
["raphael"]}]
:output-dir "working"
:output-to "public/js/main.js"})
The :file key can refer directly to a URL, or to a classpath or
working-dir relative path.
Then, in my cljs code, all I have to do to is :require ['raphael'],
and reference its constructor method with js/Raphael. (e.g, (js/
Raphael. 10 10 50 50))
It works for both :simple and :advanced modes, correctly bundling the
foreign library's source with your compiled app.
Of course, the external library still has to be compatible with Google
Closure compilation. For example, Raphael is not 100% compatible with
advanced mode. It compiles without errors, but then generates SVG
markup with munged attribute names which obviously causes problems.
The code is on my github repo at
https://github.com/levand/clojurescript.
Please tell me what you think: personally, I find this very useful and
would like to see it rolled into master.