一行命令搞定 Cloudflare Pages 自动创建 + 部署

一行命令搞定 Cloudflare Pages 自动创建 + 部署

macOS / Linux

npx wrangler pages project create <name> --production-branch main 2>/dev/null; CLOUDFLARE_API_TOKEN="xxx" npx wrangler pages deploy ./dist --project-name "<name>"

Windows PowerShell

npx wrangler pages project create <name> --production-branch main 2>$null; $env:CLOUDFLARE_API_TOKEN="xxx"; npx wrangler pages deploy ./dist --project-name "<name>"

Windows CMD

npx wrangler pages project create <name> --production-branch main 2>nul && set CLOUDFLARE_API_TOKEN=xxx && npx wrangler pages deploy ./dist --project-name "<name>"

注意:CMD 中 2>nul 会吞掉所有错误,包括真正的异常。推荐用 PowerShell 或 Git Bash。


差异速查

平台静默错误设置环境变量串联命令
macOS / Linux2>/dev/null行内直接写;
PowerShell2>$null$env:VAR="val";
CMD2>nulset VAR=val&&

使用前替换

  • <name> → 你的项目名

  • xxx → 你的 Cloudflare API Token

  • ./dist → 你的构建产物目录(如 ./build、./out)

THE END
评论 抢沙发

请登录后发表评论

    暂无评论内容