Compile and target Cloudflare Workers
Goal: understand the two emission targets and build a deployable Worker.
bynkc compile takes a --target:
| Target | Flag | What it emits | Cross-context calls |
|---|---|---|---|
| Bundle | --target bundle (default) | A flat TypeScript tree mirroring your source | Direct in-process calls |
| Workers | --target workers | One Cloudflare Worker per context | JSON calls over Service Bindings, validated at the boundary |
Bundle (default)
Section titled “Bundle (default)”bynkc compile . --output outEach 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.
Workers
Section titled “Workers”bynkc compile . --output out --target workersEach 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 configA workers build is the deployable, so it doesn’t write your unit test modules
(bynkc test compiles and stages those itself). If the project has integration
suites, which stand their contexts up as real Workers, it writes those, with a
tests/main.ts that runs just them (#1655).
The emitted directory is a standard Worker. Run it locally with Wrangler:
cd out/workers/notesnpx wrangler devOr, in one step:
bynk devdoes this whole recipe for you — compile, pick the worker, andwrangler dev— from anywhere inside the project, with nothing to provision. The manual flow above is what it runs under the hood.
An
from httpservice only produces a runnable Worker on theworkerstarget. A stateful agent compiles to a Durable Object there; onbundlethe same agent uses an in-process state registry instead.
Related
Section titled “Related”- Tutorial: Build a small HTTP service.
- Consume another context’s services with
consumes. - Reference: emission.