Vite
Deploy a Vite application to Cloudflare Workers with automatic configuration.
Minimal Example
Section titled “Minimal Example”Deploy a basic Vite app with default settings.
import { Vite } from "alchemy/cloudflare";
const app = await Vite("my-vite-app", { name: "my-vite-app", command: "bun run build",});
With Custom Bindings
Section titled “With Custom Bindings”Add database and environment bindings to the Vite app.
import { Vite, D1Database } from "alchemy/cloudflare";
const db = await D1Database("my-db", { name: "my-db",});
const app = await Vite("my-vite-app", { name: "my-vite-app", bindings: { DB: db, API_KEY: alchemy.secret(process.env.API_KEY), },});
With Custom Build Configuration
Section titled “With Custom Build Configuration”Customize the build command and output paths.
import { Vite } from "alchemy/cloudflare";
const app = await Vite("my-vite-app", { name: "my-vite-app", command: "bun run test && bun run build:production", main: "./dist/worker.js", assets: "./dist/client",});
With Transform Hook
Section titled “With Transform Hook”The transform hook allows you to customize the wrangler.json configuration. For example, adding a custom environment variable:
await Vite("my-app", { transform: { wrangler: (spec) => ({ ...spec, vars: { ...spec.vars, CUSTOM_VAR: "value", }, }), },});