Vite Plugin
Run Valet from a Vite config with one dev command.
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { valetPlugin } from 'valet-dev/vite'
export default defineConfig({
plugins: [
react(),
valetPlugin({
local: true,
enabled: true,
codegen: {
outputDir: './_generated/valet',
},
}),
],
})valetPlugin() manages the Valet dev lifecycle inside Vite. In dev it can start a local valet-server, run codegen, seed a database, and proxy browser traffic through Vite so the app only needs bun run dev. Dev logging is compact by default: one-line lifecycle updates, schema/function refresh notices, and full output only when something goes wrong.
Default defines
The plugin injects two compile-time defines by default:
__VALET_URL__— the client-facing Valet URL. In dev with the proxy enabled this is the proxy prefix, not the raw backend URL.__VALET_ENABLED__— a boolean feature flag you can use to gate Valet-backed code paths.
For TypeScript editor support, add:
// src/vite-env.d.ts
declare const __VALET_ENABLED__: boolean
declare const __VALET_URL__: stringCommon configs
Local mode
valetPlugin({
local: true,
enabled: true,
devCron: true,
seed: { script: 'bun run scripts/seed.ts' },
codegen: { outputDir: './_generated/valet' },
})local: true starts valet-server on http://127.0.0.1:3210 by default and stores the SQLite file at .data/valet.sqlite relative to the Vite root.
When devCron is enabled, Vite also runs cron jobs locally while the dev server is up by reading the generated cron.json manifest and triggering /admin/cron/run on the local Valet server.
Existing remote or shared server
valetPlugin({
url: 'https://my-app.valet.run',
enabled: true,
codegen: { outputDir: './_generated/valet' },
})In this mode the plugin skips process management and just runs codegen plus the dev proxy.
Valet contributor flow
valetPlugin({
local: {
checkout: '../valet',
dbPath: '../.data/valet/dev.sqlite',
},
codegen: { outputDir: './_generated/valet' },
})Set local.checkout to run cargo run -p valet-server from a source checkout instead of using a prebuilt binary.
Options
| Option | Default | Description |
|---|---|---|
url | VALET_URL || VALET_PROJECT_URL || http://127.0.0.1:3210 | Raw Valet server URL. |
enabled | VALET_ENABLED === '1' | Value injected into __VALET_ENABLED__ or your custom enabled define. |
local | false | Set to true or an object to spawn a local server. |
local.dbPath | VALET_DB_PATH || .data/valet.sqlite | SQLite path for the spawned local server, relative to the Vite root unless absolute. |
local.port | VALET_PORT || port from url || 3210 | Port for the spawned local server. |
local.binary | -- | Run this server binary directly. |
local.checkout | VALET_CHECKOUT | Run cargo run -p valet-server from this checkout. |
codegen.valetDir | ./valet | Directory containing schema.ts and your function files. |
codegen.outputDir | ./src/_generated/valet | Where generated bindings are written. |
codegen.watch | true in vite dev, false in vite build | Re-run codegen when files under valetDir change. |
codegen.skip | false | Disable codegen entirely. |
seed.script | -- | Shell command to run after the plugin creates a fresh local database. |
seed.force | false | Re-run the seed script on every local start. |
proxy.prefix | /__valet | Dev-server prefix that proxies to Valet. |
proxy.disabled | false | Disable the dev proxy and inject the raw URL into __VALET_URL__. |
devCron | false | Enable a Vite-managed local cron runner for vite dev. Best for local-only workflows where cron can stop when the dev server stops. |
devCron.tickIntervalMs | 1000 | Poll interval for checking due cron jobs in local dev. |
defines.url | __VALET_URL__ | Custom name for the injected URL define. |
defines.enabled | __VALET_ENABLED__ | Custom name for the injected enabled define. |
logging.mode | compact in vite dev, verbose in vite build | compact keeps Valet to one-line status updates plus warnings/errors. Use verbose to stream full Valet/codegen output. |
Existing CLI env vars
The plugin also uses the same auth and deploy env vars as the CLI when they are present:
VALET_DEPLOY_KEYis used when codegen pushes schema and handler updates to a protected remote server.VALET_AUTH_TOKENis added to proxied HTTP requests that do not already carry anAuthorizationheader.
valet-dev init compatibility
valet-dev init scaffolds imports like ../_generated/valet/api inside valet/*.ts. Because the Vite plugin's default output directory is ./src/_generated/valet, newly scaffolded projects usually want this override:
valetPlugin({
codegen: { outputDir: './_generated/valet' },
})If you prefer the default src/_generated/valet layout, update those relative imports in your valet/ files.
Reading the resolved config
The plugin instance exposes getResolvedConfig() so other Vite config code can reuse the same resolved values:
const valet = valetPlugin({ local: true })
valet.getResolvedConfig()
// {
// enabled: false,
// serverUrl: 'http://127.0.0.1:3210',
// clientUrl: '/__valet',
// ...
// }