部署到 Vercel

一、vercel.json 逐项说明

{
  "buildCommand": "node scripts/build.mjs",
  "outputDirectory": "dist",
  "redirects": [
    { "source": "/study-tour.html", "destination": "/articles.html", "permanent": true },
    { "source": "/study-tour", "destination": "/articles.html", "permanent": true }
  ],
  "headers": [
    {
      "source": "/assets/(.*)",
      "headers": [{ "key": "Cache-Control", "value": "public, max-age=604800" }]
    }
  ]
}
字段作用
buildCommandVercel 每次部署时执行的构建命令,把源码渲染成 dist/
outputDirectory站点根目录指向 dist/,Vercel 只对外提供构建产物
redirects研学页面已下线,旧地址用 301 永久跳转到文章页,保住原有收录与权重
headers图片等静态资源缓存 7 天,减少重复请求

项目没有依赖,所以不需要 installCommand,Vercel 默认的安装步骤会很快跳过。

二、方式一:Git 仓库自动部署(推荐)

  1. 把项目推送到 GitHub / GitLab / 码云。
  2. 登录 Vercel,选择 Add New → Project,导入该仓库。
  3. 框架预设选 Other;Vercel 会自动读取 vercel.json,构建命令与输出目录无需手填。
  4. 点击 Deploy,之后每次 git push 都会自动重新部署。

三、方式二:命令行部署

npm i -g vercel   # 或直接 npx vercel
vercel            # 首次会引导关联项目,生成预览环境
vercel --prod     # 发布到正式环境

四、绑定域名

在 Vercel 项目页 Settings → Domains 添加 www.tianyuan.space,按提示在域名服务商处配置 CNAME 记录;建议把裸域重定向到 www。页面里的 canonical 与 sitemap.xml 用的都是 https://www.tianyuan.space/...,域名保持一致才不会产生重复内容问题。

五、Web Analytics

页面 <head> 中的 /_vercel/insights/script.js 由 Vercel 平台提供,在项目页 Analytics 标签里开启 Web Analytics 后即可生效。该脚本与输出目录无关,改用 dist/ 作为产物后无需改动。

六、部署后自查清单

七、常见问题