Skip to content

Commit 5bdbf8c

Browse files
wrangler: document the new "redirected" configuration feature (#18757)
* wrangler: document the new "redirected" configuration feature See cloudflare/workers-sdk#7442 * fixup! wrangler: document the new "redirected" configuration feature * Update src/content/docs/workers/wrangler/configuration.mdx Co-authored-by: ToriLindsay <[email protected]> * Update src/content/docs/workers/wrangler/configuration.mdx Co-authored-by: ToriLindsay <[email protected]> * Update src/content/docs/workers/wrangler/configuration.mdx Co-authored-by: ToriLindsay <[email protected]> * Update src/content/docs/workers/wrangler/configuration.mdx Co-authored-by: ToriLindsay <[email protected]> * Update src/content/docs/workers/wrangler/configuration.mdx Co-authored-by: ToriLindsay <[email protected]> * Update src/content/docs/workers/wrangler/configuration.mdx Co-authored-by: ToriLindsay <[email protected]> * update wording in bundling doc * Review feedback updates * Review feedback updates --------- Co-authored-by: ToriLindsay <[email protected]>
1 parent a92fde0 commit 5bdbf8c

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

src/content/docs/workers/wrangler/bundling.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,10 @@ Disabling bundling is not recommended in most scenarios. Use this option only wh
7979
If your build tooling already produces build artifacts suitable for direct deployment to Cloudflare, you can opt out of bundling by using the `--no-bundle` command line flag: `npx wrangler deploy --no-bundle`. If you opt out of bundling, Wrangler will not process your code and some features introduced by Wrangler bundling (for example minification, and polyfills injection) will not be available.
8080

8181
Use [Custom Builds](/workers/wrangler/custom-builds/) to customize what Wrangler will bundle and upload to the Cloudflare global network when you use [`wrangler dev`](/workers/wrangler/commands/#dev) and [`wrangler deploy`](/workers/wrangler/commands/#deploy).
82+
83+
## Generated Wrangler configuration
84+
85+
Some framework tools, or custom pre-build processes, generate a modified Wrangler configuration to be used to deploy the Worker code.
86+
It is possible for Wrangler to automatically use this generated configuration rather than the original, user's configuration.
87+
88+
See [Generated Wrangler configuration](/workers/wrangler/configuration/#generated-wrangler-configuration) for more information.

src/content/docs/workers/wrangler/configuration.mdx

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ description: Use a configuration file to customize the
1010
---
1111

1212
import { Render, Type, MetaInfo } from "~/components";
13+
import { FileTree } from "@astrojs/starlight/components";
1314

1415
Wrangler optionally uses a `wrangler.json`/`wrangler.jsonc`/`wrangler.toml` file to customize the development and deployment setup for a Worker.
1516

@@ -1199,7 +1200,7 @@ upload_source_maps = true
11991200

12001201
## Workers Sites
12011202

1202-
<Render file="workers_sites"/>
1203+
<Render file="workers_sites" />
12031204

12041205
[Workers Sites](/workers/configuration/sites/) allows you to host static websites, or dynamic websites using frameworks like Vue or React, on Workers.
12051206

@@ -1260,3 +1261,92 @@ If you change your environment variables in the Cloudflare dashboard, Wrangler w
12601261
If you change your routes in the dashboard, Wrangler will override them in the next deploy with the routes you have set in your Wrangler configuration file. To manage routes via the Cloudflare dashboard only, remove any route and routes keys from your Wrangler configuration file. Then add `workers_dev = false` to your Wrangler configuration file. For more information, refer to [Deprecations](/workers/wrangler/deprecations/#other-deprecated-behavior).
12611262

12621263
Wrangler will not delete your secrets (encrypted environment variables) unless you run `wrangler secret delete <key>`.
1264+
1265+
## Generated Wrangler configuration
1266+
1267+
:::note
1268+
1269+
This section describes a feature that can be implemented by frameworks and other build tools that are integrating with Wrangler.
1270+
1271+
It is unlikely that an application developer will need to use this feature, but it is documented here to help you understand when Wrangler is using a generated configuration rather than the original, user's configuration.
1272+
1273+
:::
1274+
1275+
Some framework tools, or custom pre-build processes, generate a modified Wrangler configuration to be used to deploy the Worker code.
1276+
In this case, the tool may also create a special `.wrangler/deploy/config.json` file that redirects Wrangler to use the generated configuration rather than the original, user's configuration.
1277+
1278+
Wrangler uses this generated configuration only for the following deploy and dev related commands:
1279+
1280+
- `wrangler deploy`
1281+
- `wrangler dev`
1282+
- `wrangler versions upload`
1283+
- `wrangler versions deploy`
1284+
- `wrangler pages deploy`
1285+
- `wrangler pages build`
1286+
- `wrangler pages build-env`
1287+
1288+
When running these commands, Wrangler looks up the directory tree from the current working directory for a file at the path `.wrangler/deploy/config.json`.
1289+
This file must contain only a single JSON object of the form:
1290+
1291+
```json
1292+
{ "configPath": "../../path/to/wrangler.json" }
1293+
```
1294+
1295+
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.
1296+
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.
1297+
1298+
### Custom build tool example
1299+
1300+
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.
1301+
1302+
- First, the user writes code that uses Cloudflare Workers resources, configured via a user's `wrangler.toml` file.
1303+
1304+
```toml
1305+
name = "my-worker"
1306+
main = "src/index.ts"
1307+
[[kv_namespaces]]
1308+
binding = "<BINDING_NAME1>"
1309+
id = "<NAMESPACE_ID1>"
1310+
```
1311+
1312+
Note that this configuration points `main` at the user's code entry-point.
1313+
1314+
- Then, the user runs a custom build, which might read the user's `wrangler.toml` to find the source code entry-point:
1315+
1316+
```bash
1317+
> my-tool build
1318+
```
1319+
1320+
- This `my-tool` generates a `dist` directory that contains both compiled code and a new generated deployment configuration file.
1321+
It also creates a `.wrangler/deploy/config.json` file that redirects Wrangler to the new, generated deployment configuration file:
1322+
1323+
<FileTree>
1324+
1325+
- dist
1326+
- index.js
1327+
- wrangler.json
1328+
- .wrangler
1329+
- deploy
1330+
- config.json
1331+
1332+
</FileTree>
1333+
1334+
The generated `dist/wrangler.json` might contain:
1335+
1336+
```json
1337+
{
1338+
"name": "my-worker",
1339+
"main": "./index.js",
1340+
"kv_namespaces": [{ "binding": "<BINDING_NAME1>", "id": "<NAMESPACE_ID1>" }]
1341+
}
1342+
```
1343+
1344+
Note that, now, the `main` property points to the generated code entry-point.
1345+
1346+
And the `.wrangler/deploy/config.json` contains the path to the generated configuration file:
1347+
1348+
```json
1349+
{
1350+
"configPath": "../../dist/wrangler.json"
1351+
}
1352+
```

0 commit comments

Comments
 (0)