如何使用create-react-app运行构建版本? [英] How to run build version using create-react-app?

查看:154
本文介绍了如何使用create-react-app运行构建版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我使用create-react-app开发了一个小型React应用程序。 (我一直从头开始制作应用程序。)

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

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

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

有人可以告诉我如何运行生产版本而不是Dev版本吗?

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

推荐答案

当您运行 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.

这篇关于如何使用create-react-app运行构建版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆