Configuration (17)·续6

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.

  • First, the user writes code that uses Cloudflare Workers resources, configured via a user's Wrangler configuration file like the following:
  {
    "$schema": "./node_modules/wrangler/config-schema.json",
    "name": "my-worker",
    "main": "src/index.ts",
      "upload_source_maps": true,
    "vars": {
        "MY_VARIABLE": "production variable",
    },
    "env": {
        "staging": {
            "vars": {
                "MY_VARIABLE": "staging variable",
            },
        },
    },
  }
  ```

```toml
  "$schema" = "./node_modules/wrangler/config-schema.json"
  name = "my-worker"
  main = "src/index.ts"
  upload_source_maps = true

[vars]
  MY_VARIABLE = "production variable"

[env.staging.vars]
  MY_VARIABLE = "staging variable"
  ```

This configuration points `main` at the user's code entry-point and defines the `MY_VARIABLE` variable in two different environments.
- 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:

```bash
  > my-tool build --env=staging
  ```

- `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. It also creates a `.wrangler/deploy/config.json` file that redirects Wrangler to the new, generated deployment configuration file:
  - dist/
    - index.js
    - wrangler.jsonc
  - .wrangler/
    - deploy/
      - config.json

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

```json
{
    "name": "my-worker",
    "main": "./index.js",
    "vars": {
        "MY_VARIABLE": "staging variable"
    }
}

Now, the main property points to the generated code entry-point, no environment is defined, and the MY_VARIABLE variable is resolved to the staging environment value.

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

{
    "configPath": "../../dist/wrangler.jsonc"
}

Was this helpful?

YesNo

On this page

Configuration (17)·续6 - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/workers/wrangler/configuration/#page","headline":"Configuration","description":"Use a configuration file to customize the development and deployment setup for your Worker project and other Developer Platform products.","url":"https://developers.cloudflare.com/workers/wrangler/configuration/","inLanguage":"en","image":"https://developers.cloudflare.com/workers/wrangler/configuration/og.png?v=757cd9bbad5852dd","dateModified":"2026-10-20","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Customize how your code is compiled, before being processed by Wrangler. title: Custom builds image: https://developers.cloudflare.com/workers/wrangler/custom-builds/og.png?v=e5e2e1db7ef32cc8


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt
Use this file to discover all available pages before exploring further.