
Stop Baking Config Into Your React Builds — Runtime Env Vars for Containerised Frontends
You know the drill. Your React app needs an API URL. So you reach for import.meta.env.VITE_API_URL , run npm run build , and ship it. Works great — until you need to deploy the same image to staging and production with different config. Now you're building myapp:staging and myapp:prod . Two images. Two builds. The image that passed your tests is a different binary than the one going to production. Your CD pipeline is lying to you. This is the dirty secret of React containerisation : every VITE_* / REACT_APP_* / NEXT_PUBLIC_* variable is dead-end string-replaced into your bundle at build time. The browser has no process object. There is no runtime. The workarounds are all terrible: envsubst on minified JS — fragile, mutates your container filesystem fetch('/config.json') at startup — loading delays, race conditions, you're just moving the problem window.__ENV__ set via a shell script — no standard, no security model, requires Node.js or bash in your prod image There's a better way. Intr
Continue reading on Dev.to React
Opens in a new tab



