Cloudflare
Cloudflare is a Provider Selection for packages that can generate Workers, bindings, queues, workflows, schedules, storage, or sandbox output. The Definition and Runtime Helper should stay host-neutral; Cloudflare details belong in Integration Options and Provider Output.
Cloudflare boundaries
| Concern | ViteHub boundary |
|---|---|
| Workers and generated bundles | Provider Output written during production-shaped builds. |
| D1, R2, KV, Queues, Workflows, and Sandbox resources | Primitive package configuration plus Provision Steps where available. |
| Credentials | Provider env vars for provisioning or host runtime secrets through Server Env. |
| Runtime context | Runtime Host Context passed by the host integration, not app-owned global state. |
| Agent state | Agent Package state provider configuration when Cloudflare-backed state is selected. |
Configure provider-owned primitives
Use the primitive package options to select Cloudflare. The exact option belongs to the package that owns the primitive.
import { hubDb } from '@vite-hub/database/vite'
import { hubQueue } from '@vite-hub/queue/vite'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [
hubDb(),
hubQueue(),
],
database: {
driver: 'd1',
binding: 'DB',
databaseName: 'app',
},
queue: {
provider: 'cloudflare',
binding: 'JOBS',
},
})
Provision missing resources
Preview before applying.
Provision writes non-secret ids into .vitehub/provision.json; secrets remain in environment variables or provider env stores.
pnpm vitehub provision run --provider cloudflare --dry-run
CLOUDFLARE_ACCOUNT_ID=... CLOUDFLARE_API_TOKEN=... pnpm vitehub provision run --provider cloudflare
Inspect output
Cloudflare output can include worker bundles, wrangler.json, D1 bindings, queue consumers, cron triggers, and package-specific runtime imports.
Inspect output after a production-shaped build.
pnpm build
find dist -maxdepth 4 -type f | sort
Production notes
Cloudflare local development and deployed Workers do not always expose the same runtime behavior. Use Provider Output Contracts and Local Provider Runs for pull request checks, then keep Live Smoke thin against real Cloudflare deployments.
Agent Definitions can run on Cloudflare through the Agent Package's Cloudflare handler, or through generated host output where the Agent integration owns that route. Keep model keys, Durable Object state bindings, and other Runtime Env in Worker bindings.
Next steps
- Use Provisioning for resource creation.
- Use Provider output for generated artifact families.
- Use Verification for Cloudflare proof tiers.