Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/content/docs/workers/wrangler/bundling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ Disabling bundling is not recommended in most scenarios. Use this option only wh
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.

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).

## Generated Wrangler configuration

When using a framework or a custom pre-build process, some tools need to generate a modified Wrangler configuration alongside the generated code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When using a framework or a custom pre-build process, some tools need to generate a modified Wrangler configuration alongside the generated code.
When using a framework or a custom pre-build process, some tools need to generate a new Wrangler configuration alongside the original code.

My main suggestion would be to pick consistent language for what you're calling the original file and the new file because you were using a bunch of different terms and I think it could be confusing. In my edits, I went with the "new, generated file" and the "original, user's file", but you can choose something else, as long as it's consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tidied up


See [Generated Wrangler configuration](/workers/wrangler/configuration/#generated-wrangler-configuration) for more information.
92 changes: 91 additions & 1 deletion src/content/docs/workers/wrangler/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ description: Use a configuration file to customize the
---

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

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

Expand Down Expand Up @@ -1191,7 +1192,7 @@ upload_source_maps = true

## Workers Sites

<Render file="workers_sites"/>
<Render file="workers_sites" />

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

Expand Down Expand Up @@ -1252,3 +1253,92 @@ If you change your environment variables in the Cloudflare dashboard, Wrangler w
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).

Wrangler will not delete your secrets (encrypted environment variables) unless you run `wrangler secret delete <key>`.

## Generated Wrangler configuration

:::note

This section describes a feature that can be implemented by frameworks and other build tools that are integrating with Wrangler.

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 a user's configuration.

:::

When using a framework or a custom pre-build process, some tools need to generate a modified Wrangler configuration alongside the generated code.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When using a framework or a custom pre-build process, some tools need to generate a modified Wrangler configuration alongside the generated code.
When using a framework or a custom pre-build process, some tools need to generate a new Wrangler configuration alongside the original code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we actually want to say alongside generated code. The "generated config" may get stored on disk in the same directory as the "generated/compiled source code".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted to improve that.

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 configuration.

Wrangler uses this generated configuration only for the following deploy and dev related commands:

- `wrangler deploy`
- `wrangler dev`
- `wrangler versions upload`
- `wrangler versions deploy`
- `wrangler pages deploy`
- `wrangler pages build`
- `wrangler pages build-env`

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`.
This file must contain only a single JSON object of the form:

```json
{ "configPath": "../../path/to/wrangler.json" }
```

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.
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.

### Custom build tool example

A common approach that a build tool might choose to implement is to output code and configuration in a `dist` directory.
Copy link
Contributor

@ToriLindsay ToriLindsay Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A common approach that a build tool might choose to implement is to output code and configuration in a `dist` directory.
For example, a new configuration file may be generated by a custom build tool when creating a `dist` directory.

You may need to rewrite my suggestion if it doesn't make sense. I added this because I didn't quite understand the connection between this and the section above. I know it says "example" in the header, but I think it would also help to lead in by specifically saying that this is an example of when a new configuration file is generated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to make it more example-ish


- The user writes code that uses Cloudflare Workers resources, configured via a user `wrangler.toml` file.

```toml
name = "my-worker"
main = "src/index.ts"
[[kv_namespaces]]
binding = "<BINDING_NAME1>"
id = "<NAMESPACE_ID1>"
```

Note that this configuration points `main` at the user code entry-point.

- The user runs a custom build, which might read the user's `wrangler.toml` to find the source code entry-point:

```bash
> my-tool build
```

- This `my-tool` generates a `dist` directory that contains both compiled code and a new deployment configuration file.
It also generates a `.wrangler/deploy/config.json` file that redirects Wrangler to the new generated deployment configuration file:

<FileTree>

- dist
- index.js
- wrangler.json
- .wrangler
- deploy
- config.json

</FileTree>

The generated `dist/wrangler.json` might contain:

```json
{
"name": "my-worker",
"main": "./index.js",
"kv_namespaces": [{ "binding": "<BINDING_NAME1>", "id": "<NAMESPACE_ID1>" }]
}
```

Note that, now, the `main` property points to the generated code entry-point.

And the `.wrangler/deploy/config.json` contains the path to the generated configuration file:

```json
{
"configPath": "../../dist/wrangler.json"
}
```
Loading