INTEGRITY Cloudflare Docs

Custom builds

Custom builds are a way for you to customize how your code is compiled, before being processed by Wrangler.

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.

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