Skip to content

Commit

Permalink
docs: Add section about env vars in the manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Oct 23, 2024
1 parent b420d2f commit 8011a1a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/guide/essentials/config/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,26 @@ Vite provides two other environment variables, but they aren't useful in WXT pro
- `import.meta.env.BASE_URL`: Use `browser.runtime.getURL` instead.
- `import.meta.env.SSR`: Always `false`.
:::

## Manifest

To use environment variables in the manifest, you need to use the function syntax:

```ts
export default defineConfig({
extensionApi: 'chrome',
modules: ['@wxt-dev/module-vue'],
manifest: { // [!code --]
oauth2: { // [!code --]
client_id: import.meta.env.WXT_APP_CLIENT_ID // [!code --]
} // [!code --]
} // [!code --]
manifest: () => ({ // [!code ++]
oauth2: { // [!code ++]
client_id: import.meta.env.WXT_APP_CLIENT_ID // [!code ++]
} // [!code ++]
}), // [!code ++]
});
```

WXT can't load your `.env` files until after the config file has been loaded. So by using the function syntax for `manifest`, it defers creating the object until after the `.env` files are loaded into the process.

0 comments on commit 8011a1a

Please sign in to comment.