This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-24
Channels
- # announcements (5)
- # aws (5)
- # aws-lambda (6)
- # babashka (6)
- # beginners (48)
- # calva (54)
- # clj-commons (12)
- # clj-kondo (39)
- # cljfx (3)
- # cljs-dev (11)
- # clojure (91)
- # clojure-europe (25)
- # clojure-uk (3)
- # clojurescript (16)
- # cursive (2)
- # data-oriented-programming (6)
- # datomic (8)
- # emacs (10)
- # events (3)
- # fulcro (2)
- # functionalprogramming (2)
- # graalvm (4)
- # graphql (2)
- # helix (1)
- # honeysql (4)
- # jobs (1)
- # malli (4)
- # nextjournal (21)
- # off-topic (5)
- # other-languages (4)
- # overtone (3)
- # reitit (17)
- # releases (2)
- # rewrite-clj (6)
- # ring (6)
- # shadow-cljs (37)
What’s the “recommended way” for dynamic requires based on e.g. targeting node/browser? I know that shadow has embraced reader conditionals for this comes with other issues and I’m curious if there’s another answer to this question that would be worth exploring…
E.g. is there something funky you could do with .js
Closure modules to conditionally load code between node/browser? And then just use if
when you want to switch on which environment you’re on?
Is this something that is considered “in scope” for the ClojureScript compiler itself? What other tools should I look at to solve this kind of problem?
"embraced" is a overstating it. I offered it as an option. Another options is :build-options {:ns-aliases {foo.bar foo.bar-node}}
. That would make the build using this config use the foo.bar-node
ns whenever foo.bar
is required anywhere. so no change required in the code but still able to replace entire namespaces
but I believe I recommended this approach before and this is what I still recommend doing https://gist.github.com/thheller/fa044450a6470fdd1afdbcf3f37a65e3
@martinklepsch Perhaps make two namespace for browser and node that define something in the JS context that you can then use in other namespaces
Right but how would I decide which one to load? I guess I’d need different source paths for node/browser?
$ clj -M -m cljs.main -c test.a
WARNING: cljs.core/+, all arguments must be numbers, got [string string] instead at line 4 /mnt/c/Users/thheller/code/tmp/cljs-plus/src/test/a.cljs