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.
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
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!
Yes you can run npm start
command on server but there should be your node-modules . If node-modules are not present there than you can get them with npm install
command.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.