Read different .env
configs according to current command (start / test / build).
.env.dev
when npm start and npm test.env.prod
when npm run buildBy default (if custom config does not exist) read env variables from .env
file.
dotenv is using for config parsing.
Not sure about npm test
- what config file should be accepted.
But according to dotenv FAQ
No. We strongly recommend against committing your .env file to version control. It should only include environment-specific values such as database passwords or API keys. Your production database should have a different password than your development database.
No. We strongly recommend against having a "main" .env file and an "environment" .env file like .env.test. Your config should vary between deploys, and you should not be sharing values between environments.
Provide simple PR with feature implementation
馃憤
Nice improvement. It would be very useful!
@tuchk4 , I want to know: How can i use the variables which from .env file in my ES6 code?
@dioxide
These environment variables will be defined for you on process.env. For example, having an environment variable named REACT_APP_SECRET_CODE will be exposed in your JS as process.env.REACT_APP_SECRET_CODE, in addition to process.env.NODE_ENV.
Update issues according to latest PR updates
What .env* files are used?
.env
- Default.env.development
, .env.test
, .env.production
- Environment-specific settings..env.local
- Local overrides. This file is loaded for all environments except test..env.development.local
, .env.test.local
, .env.production.local
- Local overrides of environment-specific settings.Files priority (file is skipped if does not exist):
.env.test.local
, env.test
, .env.local
, .env
.env.production.local
, env.production
, .env.local
, .env
.env.development.local
, env.development
, .env.local
, .env
Priority from left to right.
Can you confirm that once this feature is built-in into create-react-app
we won't need https://www.npmjs.com/package/react-app-env anymore ?
Fixed in https://github.com/facebookincubator/create-react-app/issues/1344.
Will be out in next release.
@cadichris Yes. I will mark that package as deprecated
Please help beta test the new version that includes this change!
https://github.com/facebookincubator/create-react-app/issues/2172
Most helpful comment
Provide simple PR with feature implementation