0.2.2 • Published 2 years ago

build-worker v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

build-worker

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.

Usage

  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

It can also be used programmatically:

import { buildWorker } from 'build-worker'
await buildWorker({ entry: 'worker.js' , out: 'dist/worker.js', debug: false })

IS_CLOUDFLARE_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
}

How it works

build-worker uses the same esbuild configuration than Wrangler 2.

See https://github.com/evanw/esbuild/issues/1189.

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago