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
+25-16Lines changed: 25 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1478,33 +1478,39 @@ This file must contain only a single JSON object of the form:
1478
1478
When this `config.json` file exists, Wrangler will follow the `configPath` (relative to the `.wrangler/deploy/config.json` file) to find the generated Wrangler configuration file to load and use in the current command.
1479
1479
Wrangler will display messaging to the user to indicate that the configuration has been redirected to a different file than the user's configuration file.
1480
1480
1481
+
The generated configuration file should not include any [environments](#environments).
1482
+
This is because such a file, when required, should be created as part of a build step, which should already target a specific environment. These build tools should generate distinct deployment configuration files for different environments.
1483
+
1481
1484
### Custom build tool example
1482
1485
1483
1486
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.
1484
1487
1485
-
- First, the user writes code that uses Cloudflare Workers resources, configured via a user's Wrangler configuration file.
1488
+
- First, the user writes code that uses Cloudflare Workers resources, configured via a user's Wrangler configuration file like the following:
1486
1489
1487
-
<WranglerConfig>
1490
+
<WranglerConfig>
1488
1491
1489
-
```toml title="wrangler.toml"
1490
-
name = "my-worker"
1491
-
main = "src/index.ts"
1492
-
[[kv_namespaces]]
1493
-
binding = "<BINDING_NAME1>"
1494
-
id = "<NAMESPACE_ID1>"
1495
-
```
1492
+
```toml title="wrangler.toml"
1493
+
name = "my-worker"
1494
+
main = "src/index.ts"
1496
1495
1497
-
</WranglerConfig>
1496
+
[vars]
1497
+
MY_VARIABLE = "production variable"
1498
+
1499
+
[env.staging.vars]
1500
+
MY_VARIABLE = "staging variable"
1501
+
```
1502
+
1503
+
</WranglerConfig>
1498
1504
1499
-
Note that this configuration points `main` at the user's code entry-point.
1505
+
This configuration points `main` at the user's code entry-point and defines the `MY_VARIABLE` variable in two different environments.
1500
1506
1501
-
- Then, the user runs a custom build, which might read the user's Wrangler configuration file to find the source code entry-point:
1507
+
- Then, the user runs a custom build for a given environment (for example `staging`). This will read the user's Wrangler configuration file to find the source code entry-point and environment specific settings:
1502
1508
1503
1509
```bash
1504
-
> my-tool build
1510
+
> my-tool build --env=staging
1505
1511
```
1506
1512
1507
-
-This `my-tool` generates a `dist` directory that contains both compiled code and a new generated deployment configuration file.
1513
+
-`my-tool` generates a `dist` directory that contains both compiled code and a new generated deployment configuration file, containing only the settings for the given environment.
1508
1514
It also creates a `.wrangler/deploy/config.json` file that redirects Wrangler to the new, generated deployment configuration file:
1509
1515
1510
1516
<FileTree>
@@ -1524,11 +1530,14 @@ Note that this configuration points `main` at the user's code entry-point.
0 commit comments