add cf deploy

This commit is contained in:
Kevin
2026-05-22 16:46:13 +08:00
parent 0defc800a3
commit 8ec584d280
3 changed files with 24 additions and 10 deletions

View File

@@ -7,7 +7,9 @@
"dev": "vite", "dev": "vite",
"build": "tsc -b && vite build", "build": "tsc -b && vite build",
"preview": "vite preview", "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": { "dependencies": {
"react": "^18.3.1", "react": "^18.3.1",

9
scripts/cf-git-pages-deploy.sh Executable file
View File

@@ -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"

View File

@@ -1,14 +1,17 @@
# Git 集成时的两种常见配置: # CloudflareGit 集成 + 必填 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) 仅静态 PagesBuild = npm run buildOutput = 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" name = "hgtk-landing"
compatibility_date = "2025-05-01" 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 = "" # account_id = ""