# Staging and other modes

[← Back to Vite](https://dotenvx.com/docs/vite.md#production)

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

```dotenv
VITE_HELLO="Staging"
```

Encrypt it and provision DOTENV_PRIVATE_KEY_STAGING for your staging build job:

**npm**

```console
$ npx dotenvx encrypt -f .env.staging
```

**pnpm**

```console
$ pnpm exec dotenvx encrypt -f .env.staging
```

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

**package.json**

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

Run npm run build:staging or pnpm 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](https://vite.dev/guide/env-and-mode#modes).
