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

因此,我使用 create-response-app 开发了一个小型的 React 应用程序(我总是从头开始编写应用程序)

然后,在我对它感到满意之后,我决定运行 npm run build来进行优化的生产构建。

有没有人能告诉我如何运行生产版本而不是开发版本?

130699 次浏览

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.

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

首先在应用程序的目录中导航。

根据官方的创建反应应用程序网站。当您运行 npm run build时,您将使用应用程序的生产版本创建一个 build目录。

运行上面的命令之后,检查应用程序的构建版本的下一件事情是默认情况下安装 serve以在端口 五千上服务状态站点。

npm install -g serve
serve -s build

这将复制链接到您的剪贴板,您可以粘贴在您的浏览器,并看到您的应用程序的构建版本。

首先跑

npm install -g serve

它将在全局范围内安装服务,然后执行

serve -s build

您必须首先在全球范围内安装服务包。

如果使用的是纱线,请运行以下命令: yarn global add serve

Npm: npm install -g serve

然后执行: serve -s build

您也可以使用“服务”工具,使用“ npx”。在这种情况下,无需全局安装。

npx serve -s build