zetachang / react-native-dotenv

A Babel preset let you import application configs from .env file (zero runtime dependency)
MIT License
915 stars 68 forks source link

3 Environments and Root Directory Clean-up #7

Open AVEmedia opened 7 years ago

AVEmedia commented 7 years ago

Question 1: I have 3 environments: [development/.env], [production/.env.production], and [test/.env.test] ... I got your library dynamically switching between .env and .env.production , but how do I get it to switch between 3 environments? Three environments is very common, for example, development, staging, and production.

Question 2: I would like to store these env files in a 'config' sub-directory, but when i do, I get a bunch of ENOENT errors saying that my env files can't be located... how can I clean up my root directory by moving these env files to a folder without running into that error?

zetachang commented 7 years ago

For question 1, a solution is putting all your config in a separate folder and copy it to .env at project root in your launching script. (see the following)

{
 "scripts": {
    "ios-staging": "cp config/staging .env && npm run-ios --configuration Release"
}

For question 2, it might be a good feature to have, I would try to implement it recently.