Define custom .env files for custom development stages.
See original GitHub issueI think it would be useful to be able to define a custom .env
file.
I have three different environments my app will run on: dev
, staging
, and production
. dev
and production
are covered, but right now it doesn’t seem like there’s any easy way to have separate environment variables for other stages.
It would be handy if an additional environment variable could be specified to select the custom .env
file, and use the default .env
files if the additional variable is undefined.
e.g. (in Windows)
start: react-scripts start
- uses .env.development
start: "set REACT_APP_ENV=devstaging & react-scripts start"
- uses .env.devstaging
build_staging: "set REACT_APP_ENV=staging & react-scripts build"
- uses .env.staging
build: "react-scripts build"
- uses .env.production
The custom .env
file would be overriden by the .local
version, just how it works currently with development
, production
, and test
.
I’m not confident enough to make the change myself, but it seems like adding this would require a change in the react-scripts -> config -> jest -> env.js
file, where the dotenvFiles
variable is set (react-scripts v1.0.11).
Creating this from my comment on Issue 102 A way to define custom environment variables.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:15
- Comments:10 (6 by maintainers)
Top GitHub Comments
It looks like there’s an existing package called
env-cmd
that solves this issue: https://github.com/toddbluhm/env-cmdUsing this package you could create an env file for your environment (like
.env.staging
) and then runenv-cmd .env.staging react-scripts start
.The settings in
.env.staging
will override the settings in.env.development
.This seems like a reasonable proposal to me. I’d be happy to implement this if it’s something we want to go ahead with.