Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run build version using create-react-app?

So, I developed a small React application using create-react-app. (I have always made applications from scratch.)

Then, after I was kind of happy with it, I decided to run npm run build to make an optimized production build.

Can someone please tell me how I can run the production build instead of the Dev build?

like image 718
Raj Avatar asked Mar 10 '18 11:03

Raj


People also ask

How do I start a build version of react?

Navigate inside the directory of your app first. According to the official create-react-app website. When you run npm run build or yarn build you create a build directory with a production build of your app.

What is npm run build command?

Npm-build. The npm build is used to build a package, the synopsis is given in the next section. Synopsis npm build [<package-folder>] where <package-folder> is a folder that contains a package. json in its root.

How do I add a specific version of a create react app?

First, go to the package. json file and change the version of react , react-dom , and react-scripts to the desired version. Next, clear the node_modules and the package-lock. json file.


Video Answer


6 Answers

When you run npm run build your console should actually say something like the following

The build folder is ready to be deployed.
You may serve it with a static server:

npm install -g serve
serve -s build

The build script is building your entire app into the build folder, ready to be statically served. However actually serving it require some kind of static file server, like the the one they propose.

After running the command serve -s build you can access your production build at localhost (on the specified port).

You can of course run whatever static file server you like, I usually use express for this, however serve seems like the easiest option to just serve your statics files with a single command.

like image 178
the_cheff Avatar answered Oct 01 '22 10:10

the_cheff


Also you can use "serve" tool, using "npx". in this case no need to install it globally.

npx serve -s build
like image 34
Emad Armoun Avatar answered Oct 02 '22 10:10

Emad Armoun


Navigate inside the directory of your app first.

According to the official create-react-app website. When you run npm run build you create a build directory with a production build of your app.

After running the command above the next thing you can do to check the build version of your app is to to install serve to serve your status site on the port 5000 by default.

npm install -g serve
serve -s build

This will copy the link to your clipboard that you can paste in your browser and see the build version of you app.

like image 43
proprgrmmr Avatar answered Oct 03 '22 10:10

proprgrmmr


use this command : npm install -g serve -s build

like image 29
LogicalProgrammer Avatar answered Sep 29 '22 10:09

LogicalProgrammer


First of all run

npm install -g serve 

It will install globally the serve, and then execute

serve -s build
like image 43
Ujjwal Kumar Avatar answered Sep 30 '22 10:09

Ujjwal Kumar


You've to first install serve package globally.

If you're using yarn, run this command to do so: yarn global add serve.

For npm: npm install -g serve

And then execute: serve -s build

like image 43
Rishabh Garg Avatar answered Oct 02 '22 10:10

Rishabh Garg