timarney / react-app-rewired

Override create-react-app webpack configs without ejecting
MIT License
9.81k stars 425 forks source link

How to dynamically read .env.dev or .env.pro by different npm scripts? #469

Closed hylerrix closed 4 years ago

hylerrix commented 4 years ago

Hi, I have a problem but I don't know how to solve this elegantly:

I have two files called .env.development and .env.production, and my scripts:

"start:dev": "NODE_ENV=development react-app-rewired start",
"start:prod": "NODE_ENV=production react-app-rewired start",
"build:dev": "NODE_ENV=development react-app-rewired build",
"build:prod": "NODE_ENV=production react-app-rewired build",

Which I want is when I enter npm run start:dev or npm run build:dev, the app load .env.development file and when I enter npm run start:prod or npm run start:prod the app load .env.production file.

But I got the same result either npm run start:dev and npm run start:prod -> All the results comes from .env.development.

How to dynamically read .env.dev or .env.pro by different npm scripts?

Thx for answerinng!

hylerrix commented 4 years ago
"start:dev": "NODE_ENV=development react-app-rewired start",
"start:prod": "NODE_ENV=production react-app-rewired start",

Tried again, this way worked well, sorry to bother~