Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,20 @@ Environmental Variables can be obtained from `process.env` as usual.

Note that Vite doesn't load `.env` files by default as the files to load can only be determined after evaluating the Vite config, for example, the `root` and `envDir` options affect the loading behaviour. However, you can use the exported `loadEnv` helper to load the specific `.env` file if needed.

::: danger

If the `third` parameter of the `loadEnv()` function is an empty string : `''`, the `env` variable will contain **all the environment variables** of the application. If this variable is returned, **sensitive keys** could leak in the application's JavaScript code.

:::

```js twoslash
import { defineConfig, loadEnv } from 'vite'

export default defineConfig(({ mode }) => {
// Load env file based on `mode` in the current working directory.
// Set the third parameter to '' to load all env regardless of the
// `VITE_` prefix.
const env = loadEnv(mode, process.cwd(), '')
const env = loadEnv(mode, process.cwd(), ['VITE_', 'APP_'])
return {
// vite config
define: {
Expand Down
Loading