← All notes

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

Sources

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

Permanent ID: iil:note:fzpcy0hw

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.},
}

Markdown

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.