diff --git a/package.json b/package.json index 555517f..0443c8a 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "dev": "vite", "build": "tsc -b && vite build", "preview": "vite preview", - "deploy:pages": "bash scripts/deploy-pages.sh" + "deploy:pages": "bash scripts/deploy-pages.sh", + "deploy:cf-git": "bash scripts/cf-git-pages-deploy.sh", + "deploy:cf": "wrangler deploy" }, "dependencies": { "react": "^18.3.1", diff --git a/scripts/cf-git-pages-deploy.sh b/scripts/cf-git-pages-deploy.sh new file mode 100755 index 0000000..6e8536c --- /dev/null +++ b/scripts/cf-git-pages-deploy.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# 若必须填 Deploy command:优先填「npx wrangler deploy」(与 wrangler.toml 中 [assets] 配套)。 +# 云端已跑过 npm run build 后再执行本脚本,无需再 build。 +set -euo pipefail +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$ROOT" +PROJECT="${PAGES_PROJECT_NAME:-hgtk-landing}" +BRANCH="${CF_PAGES_BRANCH:-main}" +exec npx wrangler pages deploy dist --project-name "$PROJECT" --branch "$BRANCH" diff --git a/wrangler.toml b/wrangler.toml index 2a0bcd9..e1d30c5 100644 --- a/wrangler.toml +++ b/wrangler.toml @@ -1,14 +1,17 @@ -# Git 集成时的两种常见配置: +# Cloudflare(Git 集成 + 必填 Deploy command) +# ===================================================================== +# 供控制台「Deploy command」使用(任选其一,与下面 wrangler.toml 配套): +# npx wrangler deploy +# npm run deploy:cf +# 若更偏向经典 Pages CLI,可使用: npm run deploy:cf-git +# Build command 仍为 npm run build;输出目录 dist 会先由构建生成,再由 deploy 上传。 # -# 1) 仅静态 Pages:Build = npm run build,Output = dist,「Deploy command」留空 -# (由 Cloudflare 直接发布 dist,勿再执行 wrangler deploy) -# -# 2) Workers + Vite 管道:控制台会执行 npx wrangler deploy,要求 package.json 中 Vite ≥ 6 -# -# 下面 name 建议与 Cloudflare 控制台里的 Worker / Pages 项目名一致(你当前日志为 hgtk-landing) name = "hgtk-landing" compatibility_date = "2025-05-01" -pages_build_output_dir = "dist" -# 若 wrangler 提示需要账户 ID,可取消下行注释并填入(或与 CLOUDFLARE_ACCOUNT_ID 二选一) +[assets] +directory = "./dist" +# 客户端路由刷新时回退到 index.html(与 public/_redirects 作用一致) +not_found_handling = "single-page-application" + # account_id = ""