第 3 节:连接 GitHub 与 Cloudflare Pages(自动部署主链路)
3.1 先确认代码已在 GitHub
你的目标仓库是:adkeb/blog。
本地执行:
git remote -v
应看到:
origin git@github.com:adkeb/blog.git
如果不是这个地址,先修正 remote 再继续。
3.2 在 Cloudflare 创建 Pages 项目
操作路径(新版控制台):
- 进入
Workers & Pages - 选择
Import an existing Git repository - 选择 GitHub 账号与仓库
adkeb/blog - 生产分支选
main
3.3 构建参数必须这样填
这一项非常关键,填错就会失败:
- Framework preset:
Nuxt.js - Build command:
npm run generate - Build output directory:
dist
你之前踩过的坑:
- 填成
.output/public,会报 “build output directory not found”
原因:nuxt generate 产物在 dist,而不是 .output/public。
3.4 你曾遇到的典型错误是怎么来的
报错:
The name 'ASSETS' is reserved in Pages projects.
本质原因:
- 把 Worker 的
wrangler deploy混进了 Pages 的构建流程
正确做法:
- Pages 只做站点构建与静态发布
- Worker(如 OAuth)单独在本地/CI 用 wrangler 部署
3.5 验收方法
当你 push 到 main 后:
- Cloudflare 自动出现新 deployment
- 状态为 Success(绿色)
www.xuyangfly.site可访问
部署失败时,优先查看:
- Build command
- Output directory
- 是否有额外 deploy 命令误加