Dotenv Config
Experimental
The dotenv config and the .env.schema support are experimental and may change. See Env Files.
vp dev, vp build, vp preview, and vp test load and validate .env files against .env.schema when the file exists. The dotenv block in vite.config.ts controls that loading. See Env Files.
Both options have defaults that suit a project with .env.schema at its root. Most projects do not need this block.
Example
import { defineConfig } from 'vite-plus';
export default defineConfig({
dotenv: {
// Load and validate `.env.schema`. Defaults to `'auto'`: on when the
// project root has `.env.schema`, off otherwise.
schema: 'auto',
// Fail `vp build` when a sensitive value appears in the client output.
// Defaults to true.
scanBuildOutput: true,
},
});schema
- Type:
'auto' | boolean - Default:
'auto'
Controls whether the schema loads:
'auto': load the schema when the project root has.env.schema, or when itspackage.jsonsetsvarlock.loadPath.true: require a schema. The command fails when neither exists. Use this in a project that must never run without validation.false: never load a schema, even when the file exists. Vite's own.envhandling applies.
The project root is the root option of the config, or the working directory. To keep the schema files in another directory, set varlock.loadPath in package.json. vp dotenv and the build use the same setting. Vite's envDir option is not supported while a schema is active.
scanBuildOutput
- Type:
boolean - Default:
true
After vp build writes the client output, scan every emitted file for a plaintext copy of a sensitive value. On a match, the build fails and the scan output lists each match. Server output is not scanned. Set the option to false when every value is allowed in the output, or run vp dotenv scan yourself at another point in the pipeline.
Redaction
Log redaction and the HTTP response guard are configured in the schema, not in vite.config.ts. Use the @redact root decorator, or @sensitive={redact=false} on one variable. See the varlock documentation.