本文共 1816 字,大约阅读时间需要 6 分钟。
Deploying an app made using Next.js in production is easy. Add those 3 lines to the package.json
script
section:
在生产环境中部署使用Next.js创建的应用程序很容易。 将这三行添加到package.json
script
部分:
"scripts": { "dev": "next", "build": "next build", "start": "next start"}
We used npm run dev
up to now, to call the next
command installed locally in node_modules/next/dist/bin/next
. This started the development server, which provided us source maps and hot code reloading, two very useful features while debugging.
到目前为止,我们使用npm run dev
来调用本地安装在node_modules/next/dist/bin/next
的next
命令。 这启动了开发服务器,该服务器向我们提供了源映射和热代码重载 ,这是调试时的两个非常有用的功能。
The same command can be invoked to build the website passing the build
flag, by running npm run build
. Then, the same command can be used to start the production app passing the start
flag, by running npm run start
.
通过运行npm run build
,可以调用相同的命令来构建通过build
标记的网站。 然后,通过运行npm run start
,可以使用同一命令通过start
标志来启动生产应用程序。
Those 2 commands are the ones we must invoke to successfully deploy the production version of our site locally. The production version is highly optimized and does not come with source maps and other things like hot code reloading that would not be beneficial to our end users.
这两个命令是我们必须调用以成功在本地部署站点的生产版本的命令。 生产版本经过高度优化,并且不附带源地图和诸如热代码重新加载之类的对我们最终用户无益的东西。
So, let’s create a production deploy of our app. Build it using:
因此,让我们创建应用程序的生产部署。 使用以下命令进行构建:
npm run build
The output of the command tells us that some routes (/
and /blog
are now prerendered as static HTML, while /blog/[id]
will be served by the Node.js backend.
该命令的输出告诉我们,某些路由( /
和/blog
现在已预先呈现为静态HTML,而/blog/[id]
将由Node.js后端提供服务。
Then you can run npm run start
to start the production server locally:
然后,您可以运行npm run start
在本地启动生产服务器:
npm run start
Visiting will show us the production version of the app, locally.
访问将向我们展示该应用的生产版本。
翻译自:
转载地址:http://xlqgb.baihongyu.com/