Bundle your Cloudflare Worker with esbuild instead of webpack. (It’s ridiculously faster!)

Wrangler v1 uses webpack. Wrangler v2 is using esbuild.

Problem: Wrangler 2 is not production-ready. Solution: build-worker.


  1. Install.
    npm install build-worker
  2. Add a package.json script.

    // package.json
      "scripts": {
        "build:worker": "build-worker --entry worker.js --out dist/worker.js --debug"

    The --debug flag disables minification, making debugging much easier.

  3. Run your script.
    npm run build:worker

build-worker replaces any occurrences of IS_CLOUDFLARE_WORKER with true, which your code can use to determine whether its being run in a Cloudflare Worker:

if (IS_CLOUDFLARE_WORKER !== 'undefined' && IS_CLOUDFLARE_WORKER === true) {
  // Do something that should only happen in Cloudflare Workers
} else {
  // Do something that should not happen in Cloudflare Workers


View Github