Skip to content

Commit

Permalink
docs: clarify .env loading precedence / behavior (#18765)
Browse files Browse the repository at this point in the history
  • Loading branch information
basal-luke authored Nov 29, 2024
1 parent ae68958 commit e4a0ff1
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/guide/env-and-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional enviro

An env file for a specific mode (e.g. `.env.production`) will take higher priority than a generic one (e.g. `.env`).

Vite will always load `.env` and `.env.local` in addition to the mode-specific `.env.[mode]` file. Variables declared in mode-specific files will take precedence over those in generic files, but variables defined only in `.env` or `.env.local` will still be available in the environment.

In addition, environment variables that already exist when Vite is executed have the highest priority and will not be overwritten by `.env` files. For example, when running `VITE_SOME_KEY=123 vite build`.

`.env` files are loaded at the start of Vite. Restart the server after making changes.
Expand Down

0 comments on commit e4a0ff1

Please sign in to comment.