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
| Export | Kind | Summary |
|---|---|---|
envConfig | Function | Returns 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):
| Option | Type | Default | Summary |
|---|---|---|---|
alias | string | "#config" | Import specifier the matched per-env config file is exposed as. |
cwd | string | process.cwd() | Base directory for config discovery and .env* loading. |
envVar | string | "VITE_ENV" | Env var that selects the env name. Falls back to Vite's mode when unset or empty. |
See Guides → SPA — Vite plugin and Guides → Custom modes for the wiring.
See also
- Guides → SPA — Vite plugin (
#config) — recipe for the alias. - Guides → Custom modes (
staging,qa) — why the plugin is required for non-default modes. - Concepts →
envName()— precedence chain and the Vite gotcha.