Skip to content

Commit

Permalink
docs: add note about import.meta.env with TS (#2773)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Mar 30, 2021
1 parent 1280828 commit 77971ed
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/guide/env-and-mode.md
Expand Up @@ -51,6 +51,19 @@ Only `VITE_SOME_KEY` will be exposed as `import.meta.env.VITE_SOME_KEY` to your
- Since any variables exposed to your Vite source code will end up in your client bundle, `VITE_*` variables should _not_ contain any sensitive information.
:::

### IntelliSense

By default, Vite provides type definition for `import.meta.env`. While you can define more custom env variables in `.env.[mode]` files, you may want to get TypeScript IntelliSense for user-defined env variables which prefixed with `VITE_`.

To achieve, you can create an `env.d.ts` in `src` directory, then augment `ImportMetaEnv` like this:

```typescript
interface ImportMetaEnv {
VITE_APP_TITLE: string
// more env variables...
}
```

## Modes

By default, the dev server (`serve` command) runs in `development` mode, and the `build` command runs in `production` mode.
Expand Down

0 comments on commit 77971ed

Please sign in to comment.