timarney / react-app-rewired

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

hardcoded NODE_ENV production? #655

Closed JonathanAsbury-Dovaxis closed 2 months ago

JonathanAsbury-Dovaxis commented 4 months ago

Why are you forcing production on NODE_ENV in scripts/build.js During a development build, it causes all process.env values to exclusively load production values.

dawnmist commented 2 months ago

For a development build, you should be using the start script, not the build script.

Create-react-app also enforces NODE_ENV=build when building the app. This means you'll still have production variables enforced by create-react-app's react-scripts anyway, and is why react-app-rewired does the same thing.

From Create-react-app's documentation:

There is also a built-in environment variable called NODE_ENV. You can read it from process.env.NODE_ENV. When you run npm start, it is always equal to 'development', when you run npm test it is always equal to 'test', and when you run npm run build to make a production bundle, it is always equal to 'production'. You cannot override NODE_ENV manually. This prevents developers from accidentally deploying a slow development build to production.

You can override these variables by:

Sorry for the delay in response - Github has apparently stopped notifying me of new issues being created. 😞

JonathanAsbury-Dovaxis commented 2 months ago

Thanks for the feedback. .env.production.local is a viable option for us. We currently have to build a version that get's pushed to our dev environment. Both .env.production.local and dotenvx look like solid options. Thanks for suggesting them! I really appreciate the follow-up!