Replies: 1 comment
-
I find CRA's strategy is better, .env.* is merged but no override for existing environment variables // Load environment variables from .env* files. Suppress warnings using silent
// if this file is missing. dotenv will never modify any environment variables
// that have already been set. Variable expansion is supported in .env files.
// https://github.com/motdotla/dotenv
// https://github.com/motdotla/dotenv-expand
dotenvFiles.forEach(dotenvFile => {
if (fs.existsSync(dotenvFile)) {
require('dotenv-expand')(
require('dotenv').config({
path: dotenvFile,
})
);
}
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There are two strategies to load env vars (I choose the latter strategy in #2702), I am not sure which is better.
1 load all .env.* file and override the env
eg. you have .env and .env.local
Pros
.env.* files are merged, so you don't have to copy the entire content of .env to .env.local
Cons
vars in ~/.bashrc or specified in command line would be override, you have to write vars into any .env.* file
2 load one .env.* file but never override existing vars
eg. you have .env and .env.local
Pros
vars in ~/.bashrc or specified in command line have a higher priority than ones in .env.*
Cons
You have to copy the entire content of .env to other .env.* files.
If .env is updated, you have to copy it again. Otherwise you may run into an error.
Any idea?
Beta Was this translation helpful? Give feedback.
All reactions