I have installed react-app-rewired
as dev dependency according to docs.
"devDependencies": {
//...
"react-app-rewired": "^2.1.8",
},
Now I'd like to make a production build. When I use
NODE_ENV=production yarn install
consequent yarn build
says that react-app-rewired: not found
(because it is in dev only).
yarn build
implies production under the hood?When making the production build (when you need to transform your code, generate built assets, etc.), you usually need to have the dev dependencies installed since the dev dependencies contain the build tools needed to transform/compile the code into production code. When running the actual production code that is built from running yarn build
, then you'd only need to have the production dependencies installed.
So, before the app is actually built, you need to run yarn install
without NODE_ENV=production
. Once the app is built (i.e. once you've ran yarn build
and you have all the code transformed, all artifacts generated, etc.), then you'd re-run yarn install
but with production mode turned on (NODE_ENV=production yarn install
) so yarn only installs the dependencies in the dependencies
section of package.json
(these are the dependencies that your transformed code would depend on, whereas the build tools like react-app-rewired
are only needed at build-time).