Skip to content

部署到 Cloudflare Pages ​

1. 本地构建 ​

bash
npm install
npm run convert
npm run download-images
npm run optimize-images
npm run validate
npm run build

构建产物位于 docs/.vitepress/dist。

2. 上传到 Git 仓库 ​

将整个 javaguide-site 目录提交到 GitHub 或 GitLab 仓库。不要提交 node_modules。

3. 连接 Cloudflare Pages ​

  1. 登录 Cloudflare Dashboard。
  2. 进入 Workers & Pages。
  3. 选择 Create application → Pages → Connect to Git。
  4. 选择仓库。
  5. 配置构建参数:
    • Framework preset: VitePress
    • Build command: npm run build
    • Build output directory: docs/.vitepress/dist
    • Node version: 22 或 24
  6. 点击部署。

部署成功后会得到一个 *.pages.dev 地址。

4. 绑定自定义域名 ​

  1. 在 Pages 项目中选择 Custom domains。
  2. 添加你的域名或子域名。
  3. 按 Cloudflare 提示配置 DNS。

5. 更新内容 ​

后续更新流程:

bash
npm run convert
npm run download-images
npm run optimize-images
npm run validate
npm run build
git add .
git commit -m "update docs"
git push

Cloudflare Pages 会自动重新构建和发布。