Installation
Install the required dependencies:Configuration
import { createHandler } from "@redwoodjs/vite/worker";
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
const handler = createHandler();
return handler(request, env, ctx);
},
};
import alchemy from "alchemy";
import { D1Database, Redwood } from "alchemy/cloudflare";
const app = await alchemy("my-redwood-app");
const database = await D1Database("database", {
name: `${app.name}-${app.stage}-db`,
});
const website = await Redwood("website", {
bindings: {
DB: database,
DATABASE_URL: `d1://${database.databaseId}`,
},
});
console.log({
url: website.url,
});
await app.finalize();
Configuration Options
Properties
bindings: Cloudflare bindings (KV, R2, D1, etc.)build: Build command and environment- Default command:
rm -rf ./node_modules/.vite && vite build - Default env:
{ RWSDK_DEPLOY: "1" }
- Default command:
entrypoint: Worker entrypoint path- Default:
dist/worker/index.js
- Default:
compatibilityFlags: Cloudflare compatibility flags- Default:
["nodejs_compat"]
- Default:
compatibilityDate: Cloudflare compatibility date- Default:
2025-08-21
- Default:
wrangler.main: Path to worker source file- Default:
src/worker.tsx
- Default:
Build Process
The Redwood resource performs these build steps:- Clears Vite cache (
node_modules/.vite) - Runs Vite build with
RWSDK_DEPLOY=1 - Bundles worker code
- Outputs to
dist/worker/
Custom Build Command
Accessing Bindings
Access Cloudflare bindings in your RedwoodJS application:GraphQL Resolvers
Services
Database Integration
Use D1 Database with Prisma:Node.js Compatibility
RedwoodJS automatically enables:nodejs_compatcompatibility flag- Node.js built-in modules
- Full RedwoodJS feature set
- Prisma support
Local Development
Start the RedwoodJS dev server:- Hot module replacement
- GraphQL Playground
- Storybook integration
- Database migrations
Vite Cache Management
The default build command clears Vite cache to prevent stale builds:TypeScript Configuration
Define types for Cloudflare bindings:Deployment Best Practices
- Keep
dist/directory in.gitignore - Use D1 Database for data persistence
- Configure DATABASE_URL for Prisma
- Test migrations locally before deploying
- Clear Vite cache on build failures
Related Resources
- Website - Base resource for web applications
- D1 Database - SQL database
- KV Namespace - Key-value storage