reactjs 如何使用 create-react-app 运行构建版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49208528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run build version using create-react-app?
提问by Raj
So, I developed a small React application using create-react-app. (I have always made applications from scratch.)
因此,我使用 create-react-app 开发了一个小型 React 应用程序。(我总是从头开始制作应用程序。)
Then, after I was kind of happy with it, I decided to run npm run buildto make an optimized production build.
然后,在我对它感到满意之后,我决定运行npm run build以进行优化的生产构建。
Can someone please tell me how I can run the production build instead of the Dev build?
有人可以告诉我如何运行生产版本而不是开发版本吗?
回答by the_cheff
When you run npm run buildyour console should actually say something like the following
当您运行npm run build您的控制台时,实际上应该说如下内容
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 buildyou can access your production build at localhost (on the specified port).
运行该命令后,serve -s build您可以在 localhost(在指定端口上)访问您的生产版本。
You can of course run whatever static file server you like, I usually use express for this, however serveseems like the easiest option to just serve your statics files with a single command.
您当然可以运行您喜欢的任何静态文件服务器,我通常为此使用 express,但serve似乎是使用单个命令提供静态文件的最简单选择。
回答by LogicalProgrammer
use this command : npm install -g serve -s build
使用这个命令: npm install -g serve -s build

