Skip to content

Compile and target Cloudflare Workers

Goal: understand the two emission targets and build a deployable Worker.

bynkc compile takes a --target:

TargetFlagWhat it emitsCross-context calls
Bundle--target bundle (default)A flat TypeScript tree mirroring your sourceDirect in-process calls
Workers--target workersOne Cloudflare Worker per contextJSON calls over Service Bindings, validated at the boundary
Terminal window
bynkc compile . --output out

Each source unit becomes a .ts file, and contexts call each other directly. Use this for a single deployable unit or for running the output yourself.

Terminal window
bynkc compile . --output out --target workers

Each context becomes a directory under out/workers/<context>/:

out/workers/notes/
├── handlers.ts # your handler logic
├── index.ts # the Worker entry point + router
├── compose.ts # dependency wiring
└── wrangler.toml # Cloudflare config

The emitted directory is a standard Worker. Run it locally with Wrangler:

Terminal window
cd out/workers/notes
npx wrangler dev

Or, in one step: bynk dev does this whole recipe for you — compile, pick the worker, and wrangler dev — from anywhere inside the project, with nothing to provision. The manual flow above is what it runs under the hood.

An from http service only produces a runnable Worker on the workers target. A stateful agent compiles to a Durable Object there; on bundle the same agent uses an in-process state registry instead.