[英]How to build a next.js project and deploy it MANUALLY to Netlify?
According to the docs, Netlify supports next.js through the Essential Build Plugin and manual deployments through a CLI command , but how can I use the two together to build a next.js project in my own CI and deploy only the build output to Netlify?
插件页面提到了“链接”,即它假设项目是通过 Git 存储库连接并由 netlify 构建的,而不是由我自己的 CI 在本地构建的。
OK,终于搞定了。 将其包装起来以防其他人发现它有用:
netlify-cli
和@netlify/plugin-nextjs
netlify.toml
(确保具有publish
和functions
的路径;服务器端渲染和 API 处理程序需要functions
;这两个目录将用于构建 output构建).netlify
(另一个“临时”目录)添加到.gitignore
以从您的存储库中排除构建 outputtarget: "experimental-serverless-trace"
添加到next.config.js
netlify login
到您的帐户,运行netlify deploy --build
一次,选择一个站点名称NETLIFY_AUTH_TOKEN
(带有来自 Netlify UI 的“个人访问令牌”)和NETLIFY_SITE_ID
(在选择名称并成功完成第一次成功部署后显示在 Netlify UI 中)以绕过以后登录和选址netlify-cli
和@netlify/plugin-nextjs
yarn add -D @netlify/plugin-nextjs
yarn add -D @netlify/plugin-nextjs
netlify.toml
文件[[plugins]]
package = "@netlify/plugin-nextjs"
[build]
command = "yarn next build"
publish = ".next"
NETLIFY_AUTH_TOKEN
和NETLIFY_SITE_ID
环境变量在个人访问令牌的 Netlify 用户设置中手动生成访问令牌。 这也可以通过命令行来完成。 在终端设置或持续集成 (CI) 工具的 UI 中将令牌保存为NETLIFY_AUTH_TOKEN
环境变量。
站点 ID 在 Netlify UI 中找到:Go 到站点设置 > 常规 > 站点详细信息 > 站点信息,然后复制API ID的值,将 ID 分配给NETLIFY_SITE_ID
环境变量。
这也可以通过netlify link命令来完成。
可以通过以下命令部署到生产环境:
netlify deploy --build --prod
https://paulonteri.com/thoughts/deploy-nextjs-to-netlify-manually
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.