Custom builds
Last updated Apr 23, 2026 Custom builds are a way for you to customize how your code is compiled, before being processed by Wrangler.
Note
Wrangler runs esbuild ↗︎ by default as part of the dev and deploy commands, and bundles your Worker project into a single Worker script. Refer to Bundling.
Configure custom builds
Custom builds are configured by adding a [build] section in your Wrangler configuration file, and using the following options for configuring your custom build.
commandstringoptional- The command used to build your Worker. On Linux and macOS, the command is executed in the
shshell and thecmdshell for Windows. The&&and||shell operators may be used. This command will be run as part ofwrangler devandnpx wrangler deploy. cwdstringoptional- The directory in which the command is executed.
watch_dirstring | string\[]optional- The directory to watch for changes while using
wrangler dev. Defaults to the current working directory.
Example:
{
"build": {
"command": "npm run build",
"cwd": "build_cwd",
"watch_dir": "build_watch_dir"
}
}
[build]
command = "npm run build"
cwd = "build_cwd"
watch_dir = "build_watch_dir"
WRANGLER_COMMAND environment variable
When Wrangler runs your custom build command, it sets the WRANGLER_COMMAND environment variable so your build script can detect which Wrangler command triggered the build. This allows you to customize the build process based on the deployment context.
The possible values are:
| Value | Wrangler command triggered |
|---|---|
dev |
wrangler dev |
deploy |
wrangler deploy |
versions upload |
wrangler versions upload |
types |
wrangler types |
For example, you can use this to apply different build settings for development and production:
#!/bin/bash
if [ "$WRANGLER_COMMAND" = "dev" ]; then
echo "Building for development..."
# run a development build
else
echo "Building for production..."
# run a production build
fi
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/workers/wrangler/custom-builds/#page","headline":"Custom builds","description":"Customize how your code is compiled, before being processed by Wrangler.","url":"https://developers.cloudflare.com/workers/wrangler/custom-builds/","inLanguage":"en","image":"https://developers.cloudflare.com/workers/wrangler/custom-builds/og.png?v=e5e2e1db7ef32cc8","dateModified":"2026-04-23","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: The differences between Wrangler versions, specifically deprecations and breaking changes. title: Deprecations image: https://developers.cloudflare.com/workers/wrangler/deprecations/og.png?v=c22407eab148e3ce
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.
Docs