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
Copy file name to clipboardExpand all lines: src/content/docs/workers/wrangler/configuration.mdx
+27-13Lines changed: 27 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1304,28 +1304,36 @@ This is because such a file, when required, should be created based on a target
1304
1304
1305
1305
A common example of using a redirected configuration is where a custom build tool, or framework, wants to modify the user's configuration to be used when deploying, by generating a new configuration in a `dist` directory.
1306
1306
1307
-
- First, the user writes code that uses Cloudflare Workers resources, configured via a user's Wrangler configuration file.
1307
+
- First, the user writes code that uses Cloudflare Workers resources, configured via a user's Wrangler configuration file like the following:
1308
1308
1309
-
<WranglerConfig>
1309
+
<WranglerConfig>
1310
1310
1311
-
```toml title="wrangler.toml"
1312
-
name = "my-worker"
1313
-
main = "src/index.ts"
1314
-
[[kv_namespaces]]
1315
-
binding = "<BINDING_NAME1>"
1316
-
id = "<NAMESPACE_ID1>"
1317
-
```
1311
+
```toml title="wrangler.toml"
1312
+
name = "my-worker"
1313
+
main = "src/index.ts"
1318
1314
1319
-
</WranglerConfig>
1315
+
[[kv_namespaces]]
1316
+
binding = "<BINDING_NAME1>"
1317
+
1318
+
[vars]
1319
+
MY_VARIABLE = "production variable"
1320
+
1321
+
[env.staging.vars]
1322
+
MY_VARIABLE = "staging variable"
1323
+
```
1324
+
1325
+
</WranglerConfig>
1320
1326
1321
-
Note that this configuration points `main` at the user's code entry-point.
1327
+
Note that this configuration points `main` at the user's code entry-point and that it also defined the `MY_VARIABLE` in two different environments.
1322
1328
1323
1329
- Then, the user runs a custom build, which might read the user's Wrangler configuration file to find the source code entry-point:
1324
1330
1325
1331
```bash
1326
1332
> my-tool build
1327
1333
```
1328
1334
1335
+
We'll assume that `my-tool` is specifically targeting the `staging` environment (for instance set by the user with some API of `my-tool`).
1336
+
1329
1337
- This `my-tool` generates a `dist` directory that contains both compiled code and a new generated deployment configuration file.
1330
1338
It also creates a `.wrangler/deploy/config.json` file that redirects Wrangler to the new, generated deployment configuration file:
1331
1339
@@ -1346,11 +1354,17 @@ Note that this configuration points `main` at the user's code entry-point.
0 commit comments