Environment Variables

Addfox uses Rsbuild's loadEnv to load .env files from the project root, and by default only exposes variables starting with ADDFOX_PUBLIC_ to client code.

Default Behavior

  • Default Prefix: ADDFOX_PUBLIC_
  • Client Code: background, content, popup, options, sidepanel, devtools entries
  • Loaded Files: .env, .env.local, .env.{mode}, .env.{mode}.local

Scope

Environment variables are injected into all client code entries, but not in the manifest configuration in addfox.config.ts (which uses build-time environment).

Built-in Variables

Addfox automatically injects these variables:

VariableDescription
process.env.BROWSERCurrent build target browser
process.env.NODE_ENVCurrent environment mode
process.env.ADDFOX_VERSIONAddfox version

Usage Example

.env File

ADDFOX_PUBLIC_API_URL=https://api.example.com
ADDFOX_PUBLIC_APP_NAME=My Extension
ADDFOX_PRIVATE_KEY=secret  # Won't be exposed to client

Using in Code

// app/popup/index.tsx
const apiUrl = process.env.ADDFOX_PUBLIC_API_URL;

Security Recommendations

  • Always use ADDFOX_PUBLIC_ prefix to mark variables safe for client exposure
  • Sensitive info (like API keys) should not start with ADDFOX_PUBLIC_
  • .env.local and .env.{mode}.local files should not be committed to Git