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.example
file, with variables you want set on our environment - Add the variables from
.env.example
to.env-cmdrc.json
under 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/unplugin
that on build time (npm run build
) will substitute allimport.meta.env
from our source code to a predefined placeholder - Then running
env-cmd -e demo
(wheredemo
is 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 frombuild
with the actual environment variables