0.2.2 • Published 2 years ago
build-worker v0.2.2
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
- Install.
npm install build-worker
- 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. - 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.