Third Party Libraries In Clojurescript REPL
I ran into an issue at work earlier this week. I needed to include a phone number validation library in the Clojurescript side. It was libphonenumber by Google, which meant it was compiled with the Google closure library.
Great! That gets us halfway there.
That classifies it as a third party library, meaning in lein-cljsbuild you would specify it under the :libs key instead of the :preamble, :externs, or :foreign-libs.
I just want to make it clear that the :foreign-libs option is used for non Google closure code like jquery.
So if you're using lein-cljsbuild, it's just as easy as putting the directory path into :libs in a vector. But my problem was that I needed to access the third party library in my Clojurescript REPL while developing.
Under this documentation, it says:
I've found that to be untrue for the Rhino and Nashorn case, and I'm not completely sure if it'll work in every single scenario yet so I'm hesitent to just change the wiki. I plan on doing some more investigation and then updating the wiki so other folks that come across this entry later won't waste their time looking into the source code like I had to.
An example of how to use this with piggieback as the nrepl middleware:
(require 'cemerick.piggieback 'cljs.repl.rhino) (cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env) :libs ["resources/js"])