Vite exposes constants under the import.meta.env object, defined as globals during dev and statically replaced at build time so tree-shaking stays effective — code inside if (import.meta.env.DEV) is dropped from production builds. Built-in constants are MODE, BASE_URL (from the base config option), PROD, DEV (always the opposite of PROD), and SSR. Custom env variables appear as strings under import.meta.env, and only variables prefixed with VITE_ reach client-side source code, so avoid that prefix for anything sensitive: VITE_* values are bundled into the source at build time, and secrets belong behind a backend server or serverless functions. Parsed values are always strings even when they look numeric or boolean, so convert types yourself. Vite uses dotenv to load .env, .env.local (ignored by git), .env.[mode], and .env.[mode].local; mode-specific files take priority over generic ones, variables that already exist when Vite executes have the highest priority and are never overwritten, and dotenv-expand expands variables out of the box. Files load at startup, so restart the server after changes, and add *.local to .gitignore. Scope: Vite. Reviewed October 4, 2026.
Environment variables and modes
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- vite.dev
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.