Skip to content

Commit 6c1bbea

Browse files
update development-testing/environment-variables page
1 parent f4bb9b5 commit 6c1bbea

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/content/docs/workers/development-testing/environment-variables.mdx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,21 @@ head: []
77
description: Configuring environment variables and secrets for local development
88
---
99

10-
import { Aside, PackageManagers, Steps } from "~/components";
10+
import { Aside, PackageManagers, Render, Steps } from "~/components";
1111

12-
During local development, you may need to configure **environment variables** (such as API URLs, feature flags) and **secrets** (API tokens, private keys). You can use a `.dev.vars` file in the root of your project to override environment variables for local development, and both [Wrangler](/workers/configuration/environment-variables/#compare-secrets-and-environment-variables) and the [Vite plugin](/workers/vite-plugin/reference/secrets/) will respect this override.
12+
<Render file="secrets-in-dev" product="workers" />
1313

14-
<Aside type="caution">
15-
Be sure to add `.dev.vars` to your `.gitignore` so it never gets committed.
16-
</Aside>
14+
### Basic setup
1715

18-
### Why use a `.dev.vars` file?
19-
20-
Use `.dev.vars` to set local overrides for environment variables that should not be checked into your repository.
21-
22-
If you want to manage environment-based configuration that you **want checked into your repository** (for example, non-sensitive or shared environment defaults), you can define [environment variables as `[vars]`](/workers/wrangler/environments/#_top) in your Wrangler configuration. Using a `.dev.vars` file is specifically for local-only secrets or configuration that you do not want in version control and only want to inject in local dev sessions.
23-
24-
## Basic setup
16+
Here are steps to set up environment variables for local development using either `.dev.vars` or `.env` files.
2517

2618
<Steps>
2719

28-
1. Create a `.dev.vars` file in your project root.
20+
1. Create a `.dev.vars` / `.env` file in your project root.
2921

3022
2. Add key-value pairs:
3123

32-
```ini title=".dev.vars"
24+
```ini title=".dev.vars/.env"
3325
API_HOST="localhost:3000"
3426
DEBUG="true"
3527
SECRET_TOKEN="my-local-secret-token"
@@ -46,20 +38,23 @@ If you want to manage environment-based configuration that you **want checked in
4638

4739
</Steps>
4840

49-
## Multiple local environments with `.dev.vars`
41+
## Multiple local environments
5042

51-
To simulate different local environments, you can:
43+
To simulate different local environments, you can provide environment-specific files.
44+
For example, you might have a `staging` environment that requires different settings than your development environment.
5245

5346
<Steps>
5447

55-
1. Create a file named `.dev.vars.<environment-name>` . For example, we'll use `.dev.vars.staging`.
48+
1. Create a file named `.dev.vars.<environment-name>`/`.env.<environment-name>`. For example, we can use `.dev.vars.staging`/`.env.staging`.
5649

5750
2. Add key-value pairs:
58-
```ini title=".dev.vars.staging"
51+
52+
```ini title=".dev.vars.staging/.env.staging"
5953
API_HOST="staging.localhost:3000"
6054
DEBUG="false"
6155
SECRET_TOKEN="staging-token"
6256
```
57+
6358
3. Specify the environment when running the `dev` command:
6459

6560
**Wrangler**
@@ -70,7 +65,8 @@ To simulate different local environments, you can:
7065

7166
<PackageManagers type="exec" pkg="vite" args="dev" prefix="CLOUDFLARE_ENV=staging" />
7267

73-
Only the values from `.dev.vars.staging` will be applied instead of `.dev.vars`.
68+
- If using `.dev.vars.staging`, only the values from that file will be applied instead of `.dev.vars`.
69+
- If using `.env.staging`, the values will be merged with `.env` files, with the most specific file taking precedence.
7470

7571
</Steps>
7672

0 commit comments

Comments
 (0)