This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-11
Channels
- # adventofcode (1)
- # aleph (1)
- # announcements (3)
- # babashka (39)
- # beginners (84)
- # calva (1)
- # cider (17)
- # clj-kondo (15)
- # cljs-dev (43)
- # clojure (132)
- # clojure-dev (1)
- # clojure-europe (4)
- # clojure-nl (7)
- # clojure-norway (4)
- # clojure-uk (22)
- # clojurescript (56)
- # clojurex (24)
- # cursive (11)
- # data-science (2)
- # datascript (33)
- # datomic (7)
- # docker (2)
- # figwheel-main (11)
- # fulcro (2)
- # jobs (3)
- # joker (29)
- # leiningen (3)
- # nrepl (4)
- # off-topic (11)
- # planck (4)
- # reitit (5)
- # ring (4)
- # shadow-cljs (205)
- # spacemacs (5)
- # xtdb (9)
Somewhere near the bottom it is stated (with reference to the docs) that require
in cljs is only to be used from the repl: https://cljs.github.io/api/cljs.core/require
cljs doesn't have a resident compiler (self hosted cljs does) like clojure, which is required to provide eval and thus require
I also expect "dynamic" or "conditional" require to give problems with google advanced compilation?
Wasn't there something that the compiler tries to work with top-level requires at the start of the namespace? but that's pretty limited
@slipset the simplest answer is that ClojureScript is meant to be whole program optimized by Closure
Kinda related: is it okay to do dynamic loads for development? I was thinking of writing a user.cljs which made conditional calls to load-file.
Hmm. Frustrating. I suppose multiple ns
generated by a macro wouldn't be supported either?
@dominicm I don't understand what problem you're trying to solve - "colliding namespaces"
@dnolen I want a way to load code for my development (without modifying the project I'm on). It followed to me that user.cljs is for the user, not for projects, but projects override it anyway. So the idea was to have my user.cljs load the project user.cljs. One constraint is that it should work with a large number of projects you'd find in the wild. Consistently no matter if they're using cljsbuild, deps, etc.
I think there are two ways you can do what you want dominicm (only load some code when in development):
The first and easiest way is to use (when goog/DEBUG ...)
to define the stuff you want to happen only at DEV time. this should get DCE’d when a release build is run. This works across lein-cljsbuild/deps+figwheel/shadow-cljs
@dominicm you cannot "override" user.cljs
by the way - we'll load them all - if it doesn't work for some reason you should report a bug with some kind of minimal reproduction
I should say I haven't tested, I assumed the behavior matched clojure. I'm talking about the case that there's 2 user.cljs files on the classpath. You're saying that they're already both loaded and run? Oh, I also meant cljs/user.cljs, is that the same?
this doesn’t work when you want to optionally load a dependency (e.g. an external JS lib), so in that case you have to do something grosser,,,: - set up points in your code that should interact with the code you want to optionally load. something like:
(when (and goog/DEBUG (.-someFn js/someCoolThing))
(.someFn js/someCoolThing))
- instruct the user to add a my-lib.some-cool-thing
that sets up js/someCoolThing
into their preloads or user.cljs at DEV timeI should say I haven't tested, I assumed the behavior matched clojure. I'm talking about the case that there's 2 user.cljs files on the classpath. You're saying that they're already both loaded and run? Oh, I also meant cljs/user.cljs, is that the same?
it’s a PITA from a lib maintainer POV, but from a user POV they just need to make sure they include the side-effecting ns before any code that uses it (which is why preloads is preferred)