Skip to content
GitHubXDiscord

Vite

Deploy a Vite application to Cloudflare Workers with automatic configuration.

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",
});

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),
},
});

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",
});

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",
},
}),
},
});