Fork me on GitHub

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 {}}. That would make the build using this config use the ns whenever 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


@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?


For example yes


(ns test.a
  (:require [test.b :refer (+)]))

(+ "a" "b")


(ns test.b
  (:refer-clojure :exclude [+]))

(defn + [a b]


$ 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


that seems incorrect? the :refer (+) seems to be ignored? not sure why (tested with 1.11.4)


jira search fails me but this appears to be an issue with any core macro. cljs.analyzer/get-expander apparently ignoring :uses?