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
When building complex applications, you may need to run multiple Workers during development. This guide covers the different approaches for running multiple Workers locally and when to use each approach.
12
+
When building complex applications, you may want to run multiple Workers during development. This guide covers the different approaches for running multiple Workers locally and when to use each approach.
13
13
14
-
## Single dev session
14
+
## Single dev command
15
15
16
-
You can run multiple Workers in a single dev session by passing multiple configuration files to your dev server.
17
-
18
-
<Steps>
19
-
20
-
1. Create separate configuration files for each Worker:
21
-
22
-
**Primary Worker**
23
-
24
-
<WranglerConfig>
25
-
```toml
26
-
name = "app-worker"
27
-
main = "./src/index.ts"
28
-
29
-
[[services]]
30
-
binding = "API"
31
-
service = "api-worker"
32
-
```
33
-
</WranglerConfig>
34
-
35
-
36
-
**Auxiliary Worker**
16
+
<Asidetype="note"title="When to use this approach?">
17
+
- Workers are closely related or part of the same application
18
+
- You want the simplest development setup
19
+
- You need to access a Durable Object namespace from another Worker using `script_name`
20
+
</Aside>
37
21
38
-
<WranglerConfig>
39
-
```toml
40
-
name = "api-worker"
41
-
main = "./src/index.ts"
42
-
```
43
-
</WranglerConfig>
44
22
45
-
2. Start a dev session:
23
+
You can run multiple Workers in a single dev command by passing multiple configuration files to your dev server:
The first config (`wrangler.app.jsonc`) is treated as the primary Worker, exposed at `http://localhost:8787`. Additional configs (e.g. `wrangler.api.jsonc`) run as auxiliary Workers, available via service bindings or tail consumers from the primary Worker.
34
+
35
+
**Using the Vite plugin**
36
+
37
+
Configure `auxiliaryWorkers` in your Vite configuration:
The first config is treated as the primary Worker, exposed at `http://localhost:8787`. Additional configs run as auxiliary Workers, available via service bindings or tail consumers from the primary Worker.
57
+
Then run:
56
58
57
-
**Using the Vite plugin**
58
-
59
-
Configure `auxiliaryWorkers` in your Vite configuration:
- Workers are closely related or part of the same application
88
-
- You want the simplest development setup
89
-
- You need to access a Durable Object namespace from another Worker using `script_name`
90
-
91
-
## Multiple dev sessions
92
-
93
-
You can also run each Worker in a separate dev session, each with its own terminal and configuration.
64
+
<Asidetype="note"title="When to use this approach?">
65
+
- Each Worker uses a different build configuration
66
+
- Different teams maintain the Workers
67
+
- A Worker only occasionally accesses another, and you prefer the flexibility of running them separately
68
+
</Aside>
94
69
95
-
```sh
96
-
# Terminal 1
97
-
cd app-worker
98
-
wrangler dev
99
-
```
70
+
You can also run each Worker in a separate dev commands, each with its own terminal and configuration.
100
71
101
-
```sh
102
-
# Terminal 2
103
-
cd api-worker
104
-
wrangler dev
105
-
```
72
+
<PackageManagers
73
+
comment="Terminal 1"
74
+
type="exec"
75
+
pkg="wrangler"
76
+
args="dev -c wrangler.app.jsonc"
77
+
/>
106
78
107
-
These Workers run in different dev sessions but can still communicate with each other via service bindings or tail consumers **regardless they are started with `wrangler dev` or `vite dev`**.
79
+
<PackageManagers
80
+
comment="Terminal 2"
81
+
type="exec"
82
+
pkg="wrangler"
83
+
args="dev -c wrangler.api.jsonc"
84
+
/>
108
85
109
-
Use this approach when:
86
+
These Workers run in different dev commands but can still communicate with each other via service bindings or tail consumers **regardless of whether they are started with `wrangler dev` or `vite dev`**.
110
87
111
-
- Each Worker uses a different build configuration
112
-
- Different teams maintain the Workers
113
-
- A Worker only occasionally accesses another, and you prefer the flexibility to run them separately
88
+
### Limitations
114
89
115
-
While this setup offers flexibility, there are some limitations to be aware of when using bindings across Workers running in separate dev sessions:
90
+
While this setup offers flexibility, some bindings are not available when Workers are started in separate dev commands instead of being run together:
116
91
117
92
| Bindings | Wrangler (single config) | Wrangler (multi config) | Vite (no auxiliaryWorkers) | Vite (with auxiliaryWorkers) |
@@ -127,12 +102,14 @@ While this setup offers flexibility, there are some limitations to be aware of w
127
102
128
103
## Hybrid approach
129
104
105
+
<Asidetype="note"title="When to use this approach?">
106
+
- You have an independent Worker that is shared across multiple applications
107
+
- You are integrating with a legacy Worker that you don't want to refactor yet
108
+
- Your project structure benefits from the flexibility of both approaches
109
+
</Aside>
110
+
130
111
You can also combine both approaches — for example, run a group of Workers together through `vite dev` using `auxiliaryWorkers`, while running another Worker separately with `wrangler dev`.
131
112
132
-
This allows you to keep tightly coupled Workers in a single dev session, while treating independent or shared Workers as separate sessions. However, the same limitations for bindings apply when Workers are run across multiple dev sessions. Refer to the table above for what's supported when Workers aren't started in the same dev command.
113
+
This allows you to keep tightly coupled Workers running under a single dev command, while keeping independent or shared Workers in separate ones. However, the same [limitations](#limitations) for bindings apply when Workers are run across multiple dev commands. Refer to the table above for what's supported when Workers aren't started in the same dev command.
133
114
134
-
Use this approach when:
135
115
136
-
- You have an independent Worker that is shared across multiple applications
137
-
- You are integrating with a legacy Worker that you don't want to refactor yet
138
-
- Your project structure benefits from the flexibility of both approaches
0 commit comments