Staging and other modes

Match the encrypted file to Vite's build mode

← Back to Vite

Create .env.staging with the public values for staging:


VITE_HELLO="Staging"

Encrypt it and provision DOTENV_PRIVATE_KEY_STAGING for your staging build job:


$ npx dotenvx encrypt -f .env.staging

Commit the encrypted .env.staging file and add this script:


{
  "scripts": {
    "build:staging": "dotenvx run -f .env.staging -- vite build --mode staging"
  }
}

Run npm run build:staging, then deploy dist.

The -f flag chooses the file Dotenvx decrypts; --mode chooses Vite's mode. Keep each selected file complete: Vite also reads .env and mode-specific files, but cannot decrypt extra files itself.

Staging mode still produces an optimized production build. See Vite modes.

markdown