按照本指南,使用 Cloudflare 仪表板创建 Workers 应用。
创建 Cloudflare 账户(若尚未创建)。
要开始使用新的 Workers 应用:
-
在 Cloudflare 仪表板中,进入 Workers & Pages 页面。
Go to Workers & Pages ↗ -
选择 Create application(创建应用程序)。在此你可以:
- 从生产就绪模板库中选择
- 导入你账户中已有的 Git 仓库
- 让 Cloudflare 克隆并引导包含 Workers 应用的公开仓库。
-
连接你选择的 Git 提供商 后,配置项目并选择 Deploy(部署)。
-
Cloudflare 将启动新的构建和部署。部署完成后,可在提供的
workers.dev子域名上预览你的 Worker。
在仪表板中创建的应用已配置 Git,便于你快速启动开发工作流。要在仓库中继续开发,可运行:
# clone your repository locally
git clone <git repo URL>
# make sure you are in the root directory
cd <directory>现在,你可以通过在本地开发环境中运行 Wrangler 来预览和测试更改。准备部署时,可运行:
# adds the files to git tracking
git add .
# commits the changes
git commit -m "your message"
# push the changes to your Git provider
git push origin main如需了解更多:
- 查看我们的示例和教程获取灵感。
- 配置绑定(binding),让 Worker 与其他资源交互并解锁新功能。
- 了解如何测试和调试 Workers。
- 阅读 Workers 限制与定价。