ValetAlpha

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__: string

Common 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

OptionDefaultDescription
urlVALET_URL || VALET_PROJECT_URL || http://127.0.0.1:3210Raw Valet server URL.
enabledVALET_ENABLED === '1'Value injected into __VALET_ENABLED__ or your custom enabled define.
localfalseSet to true or an object to spawn a local server.
local.dbPathVALET_DB_PATH || .data/valet.sqliteSQLite path for the spawned local server, relative to the Vite root unless absolute.
local.portVALET_PORT || port from url || 3210Port for the spawned local server.
local.binary--Run this server binary directly.
local.checkoutVALET_CHECKOUTRun cargo run -p valet-server from this checkout.
codegen.valetDir./valetDirectory containing schema.ts and your function files.
codegen.outputDir./src/_generated/valetWhere generated bindings are written.
codegen.watchtrue in vite dev, false in vite buildRe-run codegen when files under valetDir change.
codegen.skipfalseDisable codegen entirely.
seed.script--Shell command to run after the plugin creates a fresh local database.
seed.forcefalseRe-run the seed script on every local start.
proxy.prefix/__valetDev-server prefix that proxies to Valet.
proxy.disabledfalseDisable the dev proxy and inject the raw URL into __VALET_URL__.
devCronfalseEnable a Vite-managed local cron runner for vite dev. Best for local-only workflows where cron can stop when the dev server stops.
devCron.tickIntervalMs1000Poll 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.modecompact in vite dev, verbose in vite buildcompact 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_KEY is used when codegen pushes schema and handler updates to a protected remote server.
  • VALET_AUTH_TOKEN is added to proxied HTTP requests that do not already carry an Authorization header.

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',
//   ...
// }

On this page