You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
<Renderfile="secrets-in-dev"product="workers" />
13
13
14
-
<Asidetype="caution">
15
-
Be sure to add `.dev.vars` to your `.gitignore` so it never gets committed.
16
-
</Aside>
14
+
### Basic setup
17
15
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.
25
17
26
18
<Steps>
27
19
28
-
1. Create a `.dev.vars` file in your project root.
20
+
1. Create a `.dev.vars`/ `.env`file in your project root.
29
21
30
22
2. Add key-value pairs:
31
23
32
-
```ini title=".dev.vars"
24
+
```ini title=".dev.vars/.env"
33
25
API_HOST="localhost:3000"
34
26
DEBUG="true"
35
27
SECRET_TOKEN="my-local-secret-token"
@@ -46,20 +38,23 @@ If you want to manage environment-based configuration that you **want checked in
46
38
47
39
</Steps>
48
40
49
-
## Multiple local environments with `.dev.vars`
41
+
## Multiple local environments
50
42
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.
52
45
53
46
<Steps>
54
47
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`.
56
49
57
50
2. Add key-value pairs:
58
-
```ini title=".dev.vars.staging"
51
+
52
+
```ini title=".dev.vars.staging/.env.staging"
59
53
API_HOST="staging.localhost:3000"
60
54
DEBUG="false"
61
55
SECRET_TOKEN="staging-token"
62
56
```
57
+
63
58
3. Specify the environment when running the `dev` command:
64
59
65
60
**Wrangler**
@@ -70,7 +65,8 @@ To simulate different local environments, you can:
0 commit comments