create-react-app npm run start in production mode. Maybe not possible?
Solution 1
The best option is probably to do a normal production build and then run it locally.
First install an HTTP server:
npm install serve -g
Then:
npm run build
serve -s build
By default, it will run on port 5000 so your local URL is http://localhost:5000
Solution 2
To serve the app in production mode you need to follow below steps
-
create a production build
npm run build
-
install npm serve globally
npm i -g serve
-
You may serve it with a static server now
serve -s build
You can check for more options here.
For the development in production you can enable Hot reloading in react app without ejecting
With just 3 lines of code, you can turn on HMR, but with one big caveat: React state and DOM state are not preserved between reloads. This is kind of a bummer.
You can add these lines to index.js to turn on standard Webpack HMR that doesn’t preserve state between reloads:
if (module.hot) {
module.hot.accept();
}
Read more about it here Hope it helps Thanks!
Admin
Updated on July 13, 2022Comments
-
Admin almost 2 years
I need to run the server like I simply do with:
npm run start
but I need to use the production mode. Is this possible?
In ember or angular it is possible. How to do in
create-react-app
?I tried
npm run start --prod
but nothing.