mirror of
https://github.com/vitejs/vite.git
synced 2024-11-22 07:09:05 +00:00
docs: add config env var info (#7180)
This commit is contained in:
parent
c46b56d3ef
commit
76bbcd0998
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user