3

What's the best way to create a development build bundle for a create-react-app project?

npm run build builds something that's buggy in ways that development isn't and it ignores my NODE_ENV setting

2

1 Answer 1

4

This works for the react-scripts 5.0.1:

  1. Install react-app-rewired: npm install react-app-rewired
  2. Replace the build script in your package.json:
"scripts": {
  "build": "react-app-rewired build"
}
  1. Create the config-overrides.js file in the root folder of your project.
module.exports = function override(config) {
  config.mode = 'development';
  config.optimization.minimize = false;
  return config;
};

If you want to create two build modes you can add a condition that checks the mode.

"scripts": {
  "build": "cross-env react-app-rewired build",
  "build:dev": "cross-env DEV_MODE=true react-app-rewired build",
}
module.exports = function override(config) {
  if (process.env.DEV_MODE) {
    config.mode = 'development';
    config.optimization.minimize = false;
  }
  return config;
};
Sign up to request clarification or add additional context in comments.

2 Comments

react-app-rewired worked for me for react-scripts 5 unlike many other solutions floating around. However, the part about cross-env DEV_MODE=true did not, so i was not able to reproduce the second half of this answer.
@SkyNT you would also need to install cross-env, i.e: npm install --save-dev cross-env

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.