Skip to content

Feature request - Support different env configs #1343

Closed

Description

@tuchk4

Read different .env configs according to current command (start / test / build).

  • Read .env.dev when npm start and npm test
  • Read .env.prod when npm run build

By 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.

Activity

  1. tuchk4 commented on Jan 3, 2017

    @tuchk4
    ContributorAuthor

    But according to dotenv FAQ

    Should I commit my .env file?

    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.

    Should I have multiple .env files?

    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.

  2. tuchk4 commented on Jan 3, 2017

    @tuchk4
    ContributorAuthor

    Provide simple PR with feature implementation

  3. bozheville commented on Jan 3, 2017

    @bozheville

    👍

  4. dmaslov commented on Jan 3, 2017

    @dmaslov

    Nice improvement. It would be very useful!

  5. changed the title [-]Feature request - different env config [/-] [+]Feature request - Support different env configs[/+] on Jan 23, 2017
  6. dioxide commented on Feb 20, 2017

    @dioxide

    @tuchk4 , I want to know: How can i use the variables which from .env file in my ES6 code?

  7. tuchk4 commented on Feb 20, 2017

    @tuchk4
    ContributorAuthor

    @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.

  8. tuchk4 commented on Mar 10, 2017

    @tuchk4
    ContributorAuthor

    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):

    • npm test - .env.test.local, env.test, .env.local, .env
    • npm run build - .env.production.local, env.production, .env.local, .env
    • npm start - .env.development.local, env.development, .env.local, .env

    Priority from left to right.

  9. CadiChris commented on May 12, 2017

    @CadiChris

    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 ?

  10. gaearon commented on May 12, 2017

    @gaearon
    Contributor

    Fixed in #1344.
    Will be out in next release.

  11. added this to the milestone on May 12, 2017
  12. tuchk4 commented on May 12, 2017

    @tuchk4
    ContributorAuthor

    @CadiChris Yes. I will mark that package as deprecated

  13. gaearon commented on May 16, 2017

    @gaearon
    Contributor

    Please help beta test the new version that includes this change!
    #2172

  14. locked and limited conversation to collaborators on Jan 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions