Vite puts env constants and VITE_ variables on import.meta.env
Answer: Vite exposes certain constants under the special import.meta.env object. Those constants are defined as global variables during dev and are statically replaced at build time so tree-shaking can work.
Built-in constants include import.meta.env.MODE for the current mode, BASE_URL for the base URL the app is served from, PROD and DEV for production versus development, and SSR for whether the app is running on the server.
Client-visible variables
Vite also exposes env variables on import.meta.env as strings. Variables prefixed with VITE_ are exposed in client-side source after bundling. To avoid leaking other env values to the client, do not use that prefix for secrets. VITE_SOME_KEY is a number but returns a string when parsed. You can customize the prefix with the envPrefix option.
In source
loadEnv loads .env files from envDir and merges them with matching variables already present in process.env. Its default prefix is VITE_.
See also
Claims
- id: C1 claim: Vite exposes constants on import.meta.env. source: S1 evidence: "Vite exposes certain constants under the special
import.meta.envobject."
- id: C2 claim: Variables prefixed with VITE_ are exposed to client source. source: S1 evidence: "Variables prefixed with
VITE_will be exposed in client-side source code after Vite bundling."
- id: C3 claim: loadEnv loads .env files and merges them into process.env. source: S2 evidence: "Load
.envfiles within theenvDirand merge them with the matching"
- id: C4 claim: The default env prefix is VITE_. source: S2 evidence: "prefixes: string | string[] = 'VITE_',"
Sources
- [S1] Env Variables and Modes. Vite docs. https://vite.dev/guide/env-and-mode . License: MIT. Accessed 2026-11-11.
- [S2] env loader. Vite source. https://github.com/vitejs/vite/blob/main/packages/vite/src/node/env.ts . License: MIT. Accessed 2026-11-11.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources and notices: Vite documentation and source (vitejs/vite): Copyright (c) 2019-present, VoidZero Inc. and Vite contributors; MIT (https://raw.githubusercontent.com/vitejs/vite/main/LICENSE). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Vite docs and Vite source (vitejs/vite), MIT. Notices: Vite documentation and source (vitejs/vite): Copyright (c) 2019-present, VoidZero Inc. and Vite contributors; MIT (https://raw.githubusercontent.com/vitejs/vite/main/LICENSE).
Cite this
iinventedlight. 2026. "Vite exposes env values on import.meta.env and replaces them at build time." iinventedlight Library, iil:note:fzpcy0hw, version of 2026-11-11. https://iinventedlight.com/library/notes/vite-env-and-mode/. License: CC-BY-4.0.
@misc{iil_note_fzpcy0hw,
author = {{iinventedlight}},
title = {{Vite exposes env values on import.meta.env and replaces them at build time}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-11},
url = {https://iinventedlight.com/library/notes/vite-env-and-mode/},
note = {Permanent ID iil:note:fzpcy0hw. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/vite-env-and-mode.md.