Create-react-app: Support custom .env file

Created on 10 Nov 2020  路  4Comments  路  Source: facebook/create-react-app

Describe the solution you'd like

New cra support .env file as .env and .env.{NODE_ENV}銆侻any times need to use other custom environments such as .env.qa, .env.pre an so on. Would CRA consider supporting this feature in the after-process?

I suggest that we refer to vue-cli to support --mode option, and it should be optional. When the mode option is exist, it would be replace NODE_ENV variable to load the .env file as .env.{mode}.

proposal needs triage

Most helpful comment

In case you are looking for a workaround, in our project we use env-cmd:

"scripts": {
    "start": "env-cmd -f .env.dev react-scripts start",
    "build:prod": "env-cmd -f .env.prod react-scripts build",
    "build:dev": "env-cmd -f .env.dev react-scripts build",
  },

All 4 comments

In case you are looking for a workaround, in our project we use env-cmd:

"scripts": {
    "start": "env-cmd -f .env.dev react-scripts start",
    "build:prod": "env-cmd -f .env.prod react-scripts build",
    "build:dev": "env-cmd -f .env.dev react-scripts build",
  },

@PupoSDC Thanks, does it also merge with .env file?

I had your problem and I've used the env-cmd and the Result will be merged with .env file. But I agree with you to use something like --mode flag.

I also hope to support --mode flag.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alleroux picture alleroux  路  3Comments

barcher picture barcher  路  3Comments

Evan-GK picture Evan-GK  路  3Comments

DaveLindberg picture DaveLindberg  路  3Comments

alleroux picture alleroux  路  3Comments