且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用create-react-app运行构建版本?

更新时间:2021-11-05 06:05:55

当您运行 npm run build 时,您的控制台实际上应该说类似以下内容

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

构建脚本会将您的整个应用程序构建到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.

运行命令 serve -s build 您可以在本地主机(在指定端口上)访问生产版本。

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

您当然可以运行任何您喜欢的静态文件服务器,我通常使用为此,但是 serve 似乎是最简单的选项,只需使用一个命令即可提供静态文件。

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.