feat: Add support for WXT_ environment variable prefix (#1076)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user