Foreign library dependencies - cljsjs/packages GitHub Wiki

Often JavaScript libraries depend on other libraries, for example when a library extends jQuery or builds on top of React. In these cases the dependencies should be declared as dependencies of the package:

Example:

(set-env!
  :resource-paths #{"resources"}
  :dependencies '[[cljsjs/boot-cljsjs "0.5.2" :scope "test"]
                  [cljsjs/react "15.0.0-0"]
                  [cljsjs/react-dom "15.0.0-0"]])

This ensures that the externs and foreign library declarations are available for the dependency libraries.

Additionally, when generating deps.cljs with deps-cljs one should declare :requires to the foreign library namespaces which provide the required libraries:

   (deps-cljs :name "cljsjs.react-numeric-input"
              :requires ["cljsjs.react"
                         "cljsjs.react.dom"])

This ensures that the required foreign library code is evaluated before the library code, that is, window.React is available when running React-numeric-input code.

When writing deps.cljs directly:

{:foreign-libs [{:provides ["cljsjs.react-numeric-input"]
                 :requires ["cljsjs.react" "cljsjs.react.dom"]}]
 :externs ["..."]}

Notes

  • Not all React libs depend on both React and React-DOM
  • There are existing packages that do not have dependencies or foreign-lib requires set, so you might be pointed here when updating a package