API reference

Vite

Exports from the @vlandoss/env/vite entrypoint — the Vite plugin that aliases per-environment config and injects the build's env name.

The @vlandoss/env/vite entrypoint exposes a single Vite plugin. It does two things: it makes the per-environment config file importable through the #config alias, and it injects __ENV_NAME__ so envName() returns the right value even when Vite forces NODE_ENV="production" at build time.

Exports

ExportKindSummary
envConfigFunctionReturns a Vite plugin. Adds the #config alias and the __ENV_NAME__ define.

envConfig(options?)

The env name the plugin keys off comes from VITE_ENV (read from process.env and your .env* files), falling back to Vite's mode when unset — so you can pick the env with VITE_ENV=staging vite build instead of --mode staging. See Custom modes → Selecting the env without --mode.

options (all optional):

OptionTypeDefaultSummary
aliasstring"#config"Import specifier the matched per-env config file is exposed as.
cwdstringprocess.cwd()Base directory for config discovery and .env* loading.
envVarstring"VITE_ENV"Env var that selects the env name. Falls back to Vite's mode when unset or empty.

See also

On this page