Fork me on GitHub
#shadow-cljs
<
2023-11-08
>
ingesol07:11:55

Is there a way for macros to detect if we’re in a dev or prod build at compile time?

thheller07:11:54

only in shadow-cljs, so it'll breaks elsewhere. please don't use this in libraries, but you can check (:shadow.build/mode &env)

❤️ 1
thheller07:11:59

its either :dev or :release

ingesol07:11:19

oh, nice. No chance we’re moving away from shadow anytime soon, so that’s fine 🙂

thheller07:11:12

an alternate is checking (get-in @cljs.env/*compiler* [:options :optimizations]), that'll be :none for :dev

👍 1
til 1
hifumi12321:11:46

i personally have checked the value of goog.DEBUG in macros. It may not be fool proof but it works for my use case

zeitstein12:01:43

To clarify, is the cljs.env way also tied to shadow-cljs? Does it rely on :none always being the case for :dev in shadow-cljs?

thheller14:01:18

yes, shadow-cljs forces it to :none for dev builds and you cannot change it

gratitude 1
thheller14:01:56

cljs.main/figwheel have no concept of dev/release builds though, so someone might make a :simple build and treat it as a "development build". whatever that means 🙂