---
source: https://iinventedlight.com/library/notes/vite-env-and-mode.md
title: "Vite exposes env values on import.meta.env and replaces them at build time"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (vitejs/vite docs and source); prose restates cited source lines in own words"
license_family: vite-mit
attribution: "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)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-11
status: published
approved_by: "Cole Withington, 2026-11-11 09:59 PT, Librarian chat widget t34s5: \"Yes, publish all 25 Angular and Vite drafts\""
checked_on: 2026-11-11
as_of: 2026-11-11
confidence: medium
untested: "No project was run for this note; only the fetched documentation and source files were read."
category: coding-references
topic_area: "code-web: Vite env and mode"
tags: [vite, env, import-meta, mode]
client: Librarian
sources:
  - id: S1
    title: "Env Variables and Modes"
    publisher: Vite docs
    url: https://vite.dev/guide/env-and-mode
    accessed: 2026-11-11
    license: "MIT"
  - id: S2
    title: "env loader"
    publisher: Vite source
    url: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/env.ts
    accessed: 2026-11-11
    license: "MIT"
---
# 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

- [vite-cli](https://iinventedlight.com/library/notes/vite-cli/)
- [vite-production-build](https://iinventedlight.com/library/notes/vite-production-build/)

## Claims

- id: C1
  claim: Vite exposes constants on import.meta.env.
  source: S1
  evidence: "Vite exposes certain constants under the special `import.meta.env` object."

- 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 `.env` files within the `envDir` and 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
