博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在生产中部署Next.js应用
阅读量:2503 次
发布时间:2019-05-11

本文共 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/nextnext命令。 这启动了开发服务器,该服务器向我们提供了源映射热代码重载 ,这是调试时的两个非常有用的功能。

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/

你可能感兴趣的文章
jquery简单开始
查看>>
Android:日常学习笔记(6)——探究活动(4)
查看>>
白话插件框架原理
查看>>
Using Bytecode Outline to View Java bytecode in Eclipse
查看>>
overflow: hidden用法,不仅仅是隐藏溢出
查看>>
javaweb编程思想
查看>>
Linux中cd test和cd /test以及类似命令的区别
查看>>
[BS-26] UIView、pop和Core Animation区别
查看>>
dubbo_rpc原理
查看>>
Java设计模式之《模板模式》及使用场景
查看>>
Linux编程入门
查看>>
坑爹的箭头函数
查看>>
Python 环境搭建
查看>>
IOS 在不打开电话服务的时候,可以响应服务器的推送消息,从而接收服务器的推送消息...
查看>>
置顶的博客
查看>>
ionic2 native app 更新用户头像暨文件操作
查看>>
SQL Server R2 地图报表制作(一)
查看>>
ZeroMQ——一个轻量级的消息通信组件
查看>>
JavaScript中数组和json的复制
查看>>
新概念4-30
查看>>