Skip to content

vite-env generate

Generate a .env.example file from your schema. Each variable is annotated with its type, required status, and default value.

Usage

sh
vite-env generate [config] [--output <path>]

Arguments

ArgumentTypeDefaultDescription
configstringenv.tsPath to env definition file
--outputstring.env.exampleOutput file path

Output Format

The generated file includes a comment header, then one section per group in your schema. Each variable gets a type hint line followed by the key and its default value (empty if the variable is required).

Given the example schema:

ts
import { defineEnv } from '@vite-env/core'
import { z } from 'zod'

export default defineEnv({
  client: {
    VITE_API_URL: z.url(),
    VITE_APP_NAME: z.string().min(1),
    VITE_DEBUG: z.stringbool().default(false),
    VITE_LOG_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
  },
  server: {
    DATABASE_URL: z.url(),
    JWT_SECRET: z.string().min(32),
    DB_POOL_SIZE: z.coerce.number().int().min(1).max(100).default(10),
    REDIS_URL: z.url().optional(),
  },
})

The generated .env.example looks like:

sh
# Auto-generated by @vite-env/cli — do not edit manually
# Run: npx vite-env generate

# ── Client variables (VITE_ prefix — available everywhere)
# VITE_API_URL: string — required
VITE_API_URL=
# VITE_APP_NAME: string — required
VITE_APP_NAME=
# VITE_DEBUG: boolean (true | false | 1 | 0)
VITE_DEBUG=false
# VITE_LOG_LEVEL: enum: debug | info | warn | error
VITE_LOG_LEVEL=info

# ── Server-only variables (never sent to browser)
# DATABASE_URL: string — required
DATABASE_URL=
# JWT_SECRET: string — required
JWT_SECRET=
# DB_POOL_SIZE: number
DB_POOL_SIZE=10
# REDIS_URL: string
REDIS_URL=

Committing to Version Control

Commit .env.example so teammates and CI environments know which variables the project expects:

sh
git add .env.example
git commit -m "chore: update .env.example"

Never commit .env or .env.local — those contain real secrets.

Released under the MIT License.

⚠️ You're reading unreleased (next) docs. Latest stable: v0.5.0 →