Skip to content
Open
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
37 changes: 12 additions & 25 deletions docs/guide/env-and-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,36 +192,23 @@ And create a `.env.staging` file:
VITE_APP_TITLE=My App (staging)
```

As `vite build` runs a production build by default, you can also change this and run a development build by using a different mode and `.env` file configuration:
### NODE_ENV

```[.env.testing]
NODE_ENV=development
```

### NODE_ENV and Modes

It's important to note that `NODE_ENV` (`process.env.NODE_ENV`) and modes are two different concepts. Here's how different commands affect the `NODE_ENV` and mode:
The `NODE_ENV` environment variable determines the value of the `import.meta.env.PROD` and `import.meta.env.DEV` boolean properties.

| Command | NODE_ENV | Mode |
| ---------------------------------------------------- | --------------- | --------------- |
| `vite build` | `"production"` | `"production"` |
| `vite build --mode development` | `"production"` | `"development"` |
| `NODE_ENV=development vite build` | `"development"` | `"production"` |
| `NODE_ENV=development vite build --mode development` | `"development"` | `"development"` |
Note that `NODE_ENV` does _not_ affect the Mode. `NODE_ENV` and Modes are completely distinct settings.

The different values of `NODE_ENV` and mode also reflect on its corresponding `import.meta.env` properties:
Example values of `NODE_ENV` and corresponding `import.meta.env` properties:

| Command | `import.meta.env.PROD` | `import.meta.env.DEV` |
| ---------------------- | ---------------------- | --------------------- |
| `NODE_ENV=production` | `true` | `false` |
| `NODE_ENV=development` | `false` | `true` |
| `NODE_ENV=other` | `false` | `true` |
| Command | `import.meta.env.PROD` | `import.meta.env.DEV` |
| --------------------------------- | ---------------------- | --------------------- |
| `NODE_ENV=production vite build` | `true` | `false` |
| `NODE_ENV=development vite build` | `false` | `true` |
| `NODE_ENV=other vite build` | `false` | `true` |

| Command | `import.meta.env.MODE` |
| -------------------- | ---------------------- |
| `--mode production` | `"production"` |
| `--mode development` | `"development"` |
| `--mode staging` | `"staging"` |
You can use either or both of Modes and `NODE_ENV`.
If you need help choosing one over the other, we suggest using Modes.
Modes has the advantage of supporting `.env.[mode]` files, and `NODE_ENV` is considered an antipattern by [some](https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production).

:::tip `NODE_ENV` in `.env` files

Expand Down