docs: add config env var info (#7180)

This commit is contained in:
Bjorn Lu 2022-03-05 23:14:27 +08:00 committed by GitHub
parent c46b56d3ef
commit 76bbcd0998
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,6 +96,22 @@ export default defineConfig(async ({ command, mode }) => {
})
```
### Environment Variables
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 affects the loading behaviour. However, you can use the exported `loadEnv` helper to load the specific `.env` file if needed.
```js
import { defineConfig, loadEnv } from 'vite'
export default defineConfig(({ command, mode }) => {
// Load env file based on `mode` in the current working directory
const env = loadEnv(mode, process.cwd())
return {
// build specific config
}
})
```
## Shared Options
### root