Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create-react-app npm run start in production mode. Maybe not possible?

People also ask

Can you use create react app for production?

Why it is better to avoid Create React App (CRA) CRA was created for beginners (according to Facebook) to learn React without understanding the underline configurations of Webpack. However, it is not created for production. Unfortunately, devs have been using it for all their projects.

Can I use npm With create react app?

Create React App is a comfortable environment for learning React, and is the best way to start building a new single-page application in React. npx on the first line is not a typo — it's a package runner tool that comes with npm 5.2+.

Why react app is not creating?

If you really need create-react-app , you might need to reinstall Node and reconfigure your dependencies to ensure you have a fresh start with Node, npm, npx, and the like.


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

  1. create a production build

    npm run build

  2. install npm serve globally

    npm i -g serve

  3. 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!