feat: Add support for WXT_ environment variable prefix (#1076)

This commit is contained in:
Aaron
2024-10-18 10:43:39 -05:00
committed by GitHub
parent 1fe01290c0
commit 1dbb5a468d
3 changed files with 6 additions and 5 deletions
@@ -15,14 +15,14 @@ And any environment variables listed inside them will be available at runtime:
```sh
# .env
VITE_API_KEY=...
WXT_API_KEY=...
```
```ts
await fetch(`/some-api?apiKey=${import.meta.env.VITE_API_KEY}`);
await fetch(`/some-api?apiKey=${import.meta.env.WXT_API_KEY}`);
```
Remember to prefix any environment variables with `VITE_`, otherwise they won't be available at runtime, as per [Vite's convention](https://vite.dev/guide/env-and-mode.html#env-files).
Remember to prefix any environment variables with `WXT_` or `VITE_`, otherwise they won't be available at runtime, as per [Vite's convention](https://vite.dev/guide/env-and-mode.html#env-files).
## Built-in Environment Variables
+2 -2
View File
@@ -44,8 +44,8 @@ declare module 'wxt/sandbox' {
}
export default defineAppConfig({
apiKey: import.meta.env.VITE_API_KEY,
skipWelcome: import.meta.env.VITE_SKIP_WELCOME === 'true',
apiKey: import.meta.env.WXT_API_KEY,
skipWelcome: import.meta.env.WXT_SKIP_WELCOME === 'true',
});
```
@@ -44,6 +44,7 @@ export async function createViteBuilder(
config.configFile = false;
config.logLevel = 'warn';
config.mode = wxtConfig.mode;
config.envPrefix ??= ['VITE_', 'WXT_'];
config.build ??= {};
config.publicDir = wxtConfig.publicDir;