Skip to content

Environment Variables

Dotenv Files

WXT supports dotenv files the same way as Vite. Create any of the following files:

.env
.env.local
.env.[mode]
.env.[mode].local

And any environment variables listed inside them will be available at runtime:

sh
# .env
WXT_API_KEY=...
ts
await fetch(`/some-api?apiKey=${import.meta.env.WXT_API_KEY}`);

Remember to prefix any environment variables with WXT_ or VITE_, otherwise they won't be available at runtime, as per Vite's convention.

Built-in Environment Variables

WXT provides some custom environment variables based on the current command:

UsageTypeDescription
import.meta.env.MANIFEST_VERSION2 │ 3The target manifest version
import.meta.env.BROWSERstringThe target browser
import.meta.env.CHROMEbooleanEquivalent to import.meta.env.BROWSER === "chrome"
import.meta.env.FIREFOXbooleanEquivalent to import.meta.env.BROWSER === "firefox"
import.meta.env.SAFARIbooleanEquivalent to import.meta.env.BROWSER === "safari"
import.meta.env.EDGEbooleanEquivalent to import.meta.env.BROWSER === "edge"
import.meta.env.OPERAbooleanEquivalent to import.meta.env.BROWSER === "opera"

You can also access all of Vite's environment variables:

UsageTypeDescription
import.meta.env.MODEstringThe mode the extension is running in
import.meta.env.PRODbooleanWhen NODE_ENV='production'
import.meta.env.DEVbooleanOpposite of import.meta.env.PROD
Other Vite Environment Variables

Vite provides two other environment variables, but they aren't useful in WXT projects:

  • import.meta.env.BASE_URL: Use browser.runtime.getURL instead.
  • import.meta.env.SSR: Always false.