So say I want to use fabric through cljsjs. I've put [cljsjs/fabric "1.5.0-1"]
in the dependencies vector of project.clj
. But after restarting leiningen/figwheel I'm told that "there's no such namespace cljsjs/fabric" when running (ns fab-test.core (:require cljsjs/fabric))
.
What am I doing wrong?
@rovanion The foreign-lib ("namespace") names don't use /
, the correct name is cljsjs.fabric
Sorry, that was a pretty obvious typo. But I'm back to the error message I had previously today: That cljsjs is not defined.
Though it is loaded into the browser, I can access fabric.Canvas in the console and js/fabric.Canvas
in cljs.
(ns fab5.core
(:require [cljsjs.fabric :as fab]))
(prn js/fabric.Canvas) ; => #object[klass]
(prn fab/Canvas) ; => #object[ReferenceError ReferenceError: cljsjs is not defined]
@rovanion Fabric package doesn't support :global-exports
so you can't use :as
alias with it, you need to access it through the global
Ahh, thank you @juhoteperi!
If you want, you could add
{:file "cljsjs/fabric/development/fabric.inc.js",
:provides ["cljsjs.fabric"],
:global-exports {cljsjs.fabric Fabric}
:file-min "cljsjs/fabric/production/fabric.min.inc.js"}
To :foreign-libs
in compiler-options to use global-exports (remember to quote symbols in global-exports depending where you set this)Reagent changelog and alpha upgrade guide might be the best resources related to this, for now: https://github.com/reagent-project/reagent/blob/master/docs/0.8-upgrade.md
In my project.clj or (based on some googling) in a src/deps.cljs file in the cljsjs package?
you can overwrite the deps.cljs options from cljsjs packages, in your own cljs compiler-options, e.g. in your project.clj, when using lein
Though you can use global-exports like this, it might be best to just use the old way (access through the global object) until the new features are ironed out 🙂
Right, this seems a bit complex for just playing around.