react-native-dotenv icon indicating copy to clipboard operation
react-native-dotenv copied to clipboard

Feature request: Support `.env*.local` as overrides

Open vtsatskin opened this issue 8 years ago • 2 comments

To follow the convention set in create-react-app, I'm proposing the following additional environment files:

  • .env.local which overrides .env
  • env.development.local which overrides .env.development
  • .env.production.local which overrides .env.production.local

These would not be mutually exclusive so the following

# .env
A=hello world
B=1
# .env.local
B=2

Would result in the following environment variables:

A=hello world
B=2

Let me know if this feature would be accepted into the main branch and I'll make a PR. Guidance on how this would be implemented would also be appreciated.

vtsatskin avatar Nov 11 '17 16:11 vtsatskin

From reading the source code, what happens when there are both .env and .env.development files present?

From my understanding, the development and production files are mutually exclusive. So that means that we would have to diverge slightly from the create-react-app's behaviour of the following:

Files on the left have more priority than files on the right: [development]: .env.development.local, .env.development, .env.local, .env [production]: .env.production.local, .env.production, .env.local, .env

Instead we would probably have to go with

Files on the left have more priority than files on the right: [development]: .env.development.local, .env.development, .env.local, .env [production]: .env.production.local, .env.production

vtsatskin avatar Nov 11 '17 16:11 vtsatskin

+1 for this. I think CRA do the go job of priority of .env https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#what-other-env-files-can-be-used

mike623 avatar Jan 17 '18 02:01 mike623