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.
Thank you for this! With little Java experience I was tripped up by
(io/resource "config.edn")
, which apparently expects to findconfig.edn
on the classpath. My config is in the project root so I removed that line and changed the following sexp to(aero/read-config "config.edn" {:profile release-flag})
(aero docs)