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

余生长醉 提交于 2019-12-08 15:50:38

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/49208528/how-to-run-build-version-using-create-react-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!