Objectives/approach
- Load config conditionally, based on a release flag passed in at the command line. We use juxt/aero to read a static
config.edn
file, passing in the release flag as aero's:profile
. - Config should be exposed at runtime (in the browser / cljs) and macro-expansion time (clj). We store config in a plain map,
app.env/config
. Our build hook,app.build/load-env
, updates this usingalter-var-root!
. - Whenever config has changed, shadow-cljs must invalidate its caches so that changes are picked up immediately. We do this in
app.build/load-env
by putting the current environment in the shadow build state, under[:compiler-options :external-config ::env]
.
Why this approach?
- Reading config directly from macros breaks compiler caching - changing config will not cause changes to propagate to the build.
:clojure-defines
(ie.goog-define
) are not exposed inclj
, & therefore can't be used by macros. We want one single way to expose config that can be reliably read anywhere.- Setting the release flag from the command line makes it easy to integrate this build flow with various deployment scripts/approaches.
a bit late tho when I first looked at it I was "meh" ... too much work, tho on trying EVERYTHING else (it's not lost how much MORE effort that was), some reflection, and acceptance, ... it's precisely what was needed, thank you