cloudflare-worker-builder by jezweb/claude-skills
npx skills add https://github.com/jezweb/claude-skills --skill cloudflare-worker-builder通过简要描述快速搭建一个可运行的 Cloudflare Worker 项目。生成一个包含 Hono 路由、Vite 开发服务器和静态资源的可部署项目。
询问项目详情以选择合适的绑定和结构:
类似“带数据库的待办事项应用”这样的简要描述就足以继续。
npm create cloudflare@latest my-worker -- --type hello-world --ts --git --deploy false --framework none
cd my-worker
npm install hono
npm install -D @cloudflare/vite-plugin vite
复制并自定义此技能 assets/ 目录中的资源文件:
wrangler.jsonc — Worker 配置vite.config.ts — Vite + Cloudflare 插件src/index.ts — 包含静态资源回退的 Hono 应用广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
package.json — 脚本和依赖项tsconfig.json — TypeScript 配置public/index.html — SPA 入口点根据项目需求向 wrangler.jsonc 添加绑定。Wrangler 4.45+ 在首次部署时会自动预配资源 — 请务必指定明确的名称:
{
"name": "my-worker",
"main": "src/index.ts",
"compatibility_date": "2025-11-11",
"assets": {
"directory": "./public/",
"binding": "ASSETS",
"not_found_handling": "single-page-application",
"run_worker_first": ["/api/*"]
},
// 按需添加:
"d1_databases": [{ "binding": "DB", "database_name": "my-app-db" }],
"r2_buckets": [{ "binding": "STORAGE", "bucket_name": "my-app-files" }],
"kv_namespaces": [{ "binding": "CACHE", "title": "my-app-cache" }]
}
npm run dev # 本地开发,地址为 http://localhost:8787
wrangler deploy # 生产环境部署
// 正确 — 使用此模式
export default app
// 错误 — 会导致“Cannot read properties of undefined”
export default { fetch: app.fetch }
如果没有 run_worker_first,SPA 回退会拦截 API 路由并返回 index.html 而不是 JSON:
"assets": {
"not_found_handling": "single-page-application",
"run_worker_first": ["/api/*"] // 关键
}
import { defineConfig } from 'vite'
import { cloudflare } from '@cloudflare/vite-plugin'
export default defineConfig({ plugins: [cloudflare()] })
务必在 wrangler.jsonc 中设置 main 字段 — Vite 插件需要它。
添加 cron 触发器时,切换到显式导出:
export default {
fetch: app.fetch,
scheduled: async (event, env, ctx) => { /* ... */ }
}
阅读以下文件以进行详细故障排除:
references/common-issues.md — 10 个有来源和修复方案的已记录问题references/architecture.md — 路由优先级、缓存、Workers RPCreferences/deployment.md — CI/CD、自动预配、渐进式发布每周安装量
445
代码仓库
GitHub 星标数
643
首次出现
2026年2月18日
安全审计
安装于
opencode401
github-copilot397
codex396
gemini-cli394
cursor390
kimi-cli385
Scaffold a working Cloudflare Worker project from a brief description. Produces a deployable project with Hono routing, Vite dev server, and Static Assets.
Ask about the project to choose the right bindings and structure:
A brief like "todo app with database" is enough to proceed.
npm create cloudflare@latest my-worker -- --type hello-world --ts --git --deploy false --framework none
cd my-worker
npm install hono
npm install -D @cloudflare/vite-plugin vite
Copy and customise the asset files from this skill's assets/ directory:
wrangler.jsonc — Worker configurationvite.config.ts — Vite + Cloudflare pluginsrc/index.ts — Hono app with Static Assets fallbackpackage.json — Scripts and dependenciestsconfig.json — TypeScript configpublic/index.html — SPA entry pointAdd bindings to wrangler.jsonc based on project needs. Wrangler 4.45+ auto-provisions resources on first deploy — always specify explicit names:
{
"name": "my-worker",
"main": "src/index.ts",
"compatibility_date": "2025-11-11",
"assets": {
"directory": "./public/",
"binding": "ASSETS",
"not_found_handling": "single-page-application",
"run_worker_first": ["/api/*"]
},
// Add as needed:
"d1_databases": [{ "binding": "DB", "database_name": "my-app-db" }],
"r2_buckets": [{ "binding": "STORAGE", "bucket_name": "my-app-files" }],
"kv_namespaces": [{ "binding": "CACHE", "title": "my-app-cache" }]
}
npm run dev # Local dev at http://localhost:8787
wrangler deploy # Production deploy
// CORRECT — use this pattern
export default app
// WRONG — causes "Cannot read properties of undefined"
export default { fetch: app.fetch }
Source: honojs/hono #3955
Without run_worker_first, SPA fallback intercepts API routes and returns index.html instead of JSON:
"assets": {
"not_found_handling": "single-page-application",
"run_worker_first": ["/api/*"] // CRITICAL
}
Source: workers-sdk #8879
import { defineConfig } from 'vite'
import { cloudflare } from '@cloudflare/vite-plugin'
export default defineConfig({ plugins: [cloudflare()] })
Always set the main field in wrangler.jsonc — the Vite plugin needs it.
When adding cron triggers, switch to explicit export:
export default {
fetch: app.fetch,
scheduled: async (event, env, ctx) => { /* ... */ }
}
Read these for detailed troubleshooting:
references/common-issues.md — 10 documented issues with sources and fixesreferences/architecture.md — Route priority, caching, Workers RPCreferences/deployment.md — CI/CD, auto-provisioning, gradual rolloutsWeekly Installs
445
Repository
GitHub Stars
643
First Seen
Feb 18, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode401
github-copilot397
codex396
gemini-cli394
cursor390
kimi-cli385
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
138,300 周安装
Rust调用关系图生成器 - 可视化函数调用层次结构,提升代码分析效率
539 周安装
parallel-web-extract:并行网页内容提取工具,高效抓取网页数据
595 周安装
腾讯云CloudBase AI模型Web技能:前端调用混元/DeepSeek模型,实现流式文本生成
560 周安装
Apollo Connectors 模式助手:GraphQL API 连接器开发与集成指南
565 周安装
GitHub Trending 趋势分析工具:实时发现热门项目、技术洞察与开源机会
556 周安装
GSAP React 集成教程:useGSAP Hook 动画库与 React 组件开发指南
546 周安装