I'm trying to wrap my head around using "foreign" JavaScript dependencies in Clojurescript. I've read most everything Google has to offer on this topic but I still fail to understand this process. In particular, I'm interested how to depend on the jsonld.js library from Clojurescript.
Some points I don't get:
Do you put
:foreign-libsinto deps.cljs or compiler options (e.g.,:compilermap in project.clj)?Is the value of
:filein:foreign-libsinterpreted as a Java resource? Where do you put the JavaScript files you use as foreign libraries? I tried putting them intoresourcesand elsewhere, but all my attempts resulted injava.lang.NullPointerException.
Steps to reproduce:
# Create an empty Clojurescript project
lein new figwheel jsonld
# Download jsonld.js library
cd jsonld/resources
curl -O http://cdnjs.cloudflare.com/ajax/libs/jsonld/0.3.15/jsonld.js
# Configure foreign libs in project.clj.
# Add the following into `:compiler` in the dev build:
# :foreign-libs {:file "resources/jsonld.js"
# :provides ["jsonld"]}
lein figwheel # => java.lang.NullPointerException
Alternatively, if I provide deps.cljs with the following content:
{:foreign-libs {:file "jsonld.js"
:provides ["jsonld"]}}
Then Figwheel starts, but when I call (require '[jsonld]), I get this error:
WARNING: JavaScript file found on classpath for library `jsonld`, but does not contain a corresponding `goog.provide` declaration
clojure.lang.ExceptionInfo: No such namespace: jsonld, could not locate jsonld.cljs, jsonld.cljc, or Closure namespace "jsonld" {:tag :cljs/analysis-error}