Description
💚 The custom environment variables feature.
Update February 2017: We devised a solution for runtime config on Heroku. create-react-app-buildpack now supports runtime environment variables by way of injecting values into the javascript bundle at runtime. This is still an open question for other runtimes and deployment techniques.
This feature leverages Webpack's DefinePlugin which is explained as:
…global constants which can be configured at compile time.
The issue is not all configuration should be compiled into an application.
Things that are stable between environments (dev, staging, production) of an app make sense to compile-in:
- version number
- commit sha/number
- browser support flags
Things that change between environments would be better provided dynamically from the current runtime:
- URLs of an APIs (may change for each environment)
- secret tokens (may change for each user or request)
Ideally a bundle could be tested in CI, then promoted through environments to production, but compiling all of these values into the bundle means that every promotion requires rebuild.
I've used Node to serve single-page apps in the past with a base HTML template that gets environment variables set via inline <script>
at runtime; even used a server-side Redux reducer to capture process.env
values into an initial state.
Now, I'm trying to find a good solution to the conflation of runtime configuration values being compiled into the bundle.
create-react-app
is clearly focused on producing a bundle that can be used anywhere.
Is this project open to solutions/hooks for injecting runtime variables, or is this wandering into npm run eject
territory?