Have a single build with possibility of switching between environment variables without actually rebuilding the entire app
Environment variables are inside the .env-cmdrc.json file. Currently there are 3 environments (dev, staging, demo).
- Define a
.env.examplefile, with variables you want set on our environment - Add the variables from
.env.exampleto.env-cmdrc.jsonunder each environment - Build the application
npm run build - Preview the build on different environments with
npm run start:staging,npm run start:demo, etc.
- Using
@import-meta-env/unpluginthat on build time (npm run build) will substitute allimport.meta.envfrom our source code to a predefined placeholder - Then running
env-cmd -e demo(wheredemois a environment from.env-cmdrc.json) will set up the environment variables for us - Then running
import-meta-env --example .env.example -o "build/**/*"will substitute the predefined placeholder frombuildwith the actual environment variables