# Bundler API
URL: /docs/api/bundler
Bundler API [#bundler-api]
Use the bundler API when configuring how JS/TS kernel inputs are bundled and executed. Bundlers resolve imports, transpile code, and produce executable bundles for the kernel runtime.
Types [#types]
| undefined",
"simplifiedType": "Record",
"required": false,
"deprecated": false
}
]
}}
/>
> | undefined",
"simplifiedType": "object",
"required": false,
"deprecated": false
},
{
"name": "initialize",
"description": "Initialize the bundler. Receives framework init options plus user-provided options.",
"tags": [],
"type": "(initOptions: BundlerInitOptions, options: Options) => Promise",
"simplifiedType": "function",
"required": true,
"deprecated": false
},
{
"name": "detectImports",
"description": "Detect which bare-specifier modules are imported transitively.\nResolves relative imports normally but marks bare specifiers as external.\nReturns detected modules and project dependencies without producing runnable code.\nThis is the primary mechanism for kernel selection -- no module stubs required.",
"tags": [],
"type": "(input: BundleInput, context: Context) => Promise",
"simplifiedType": "function",
"required": true,
"deprecated": false
},
{
"name": "bundle",
"description": "Produce runnable code with all registered modules resolved.\nCalled AFTER kernel selection and initialization (modules are registered).",
"tags": [],
"type": "(input: BundleInput, context: Context) => Promise",
"simplifiedType": "function",
"required": true,
"deprecated": false
},
{
"name": "execute",
"description": "Execute bundled code (tied to this bundler's output format).",
"tags": [],
"type": "(code: string, context: Context) => Promise",
"simplifiedType": "function",
"required": true,
"deprecated": false
},
{
"name": "registerModule",
"description": "Register a builtin module for resolution during bundle().",
"tags": [],
"type": "(name: string, builtinModule: BuiltinModule, context: Context) => void",
"simplifiedType": "function",
"required": true,
"deprecated": false
},
{
"name": "resolveDependencies",
"description": "Optional fast-path dependency resolution without full bundling.\nFalls back to bundle().dependencies when not implemented.",
"tags": [],
"type": "((input: BundleInput, context: Context) => Promise) | undefined",
"simplifiedType": "function",
"required": false,
"deprecated": false
},
{
"name": "cleanup",
"description": "Clean up bundler resources (e.g., esbuild.stop()).",
"tags": [],
"type": "((context: Context) => Promise) | undefined",
"simplifiedType": "function",
"required": false,
"deprecated": false
}
]
}}
/>
Promise",
"simplifiedType": "function",
"required": true,
"deprecated": false
},
{
"name": "resolveDependencies",
"description": "Resolve all transitive dependencies without generating output code.\nReturns both resolved dependencies and unresolved import paths.",
"tags": [],
"type": "(entryPath: string) => Promise",
"simplifiedType": "function",
"required": true,
"deprecated": false
},
{
"name": "registerModule",
"description": "Register a built-in module that will be served from memory during bundling.\nUsed by JS/TS kernels to register WASM-loaded libraries (replicad,",
"tags": [
{
"name": "jscad",
"text": "/modeling).\nMust be called before the first bundle() call."
}
],
"type": "(name: string, entry: BuiltinModule) => void",
"simplifiedType": "function",
"required": true,
"deprecated": false
}
]
}}
/>
esbuild [#esbuild]
`esbuild()` returns a `BundlerPlugin` that uses esbuild-wasm for bundling. Handles `ts`, `js`, `tsx`, `jsx` by default.
defineBundler [#definebundler]
`defineBundler` creates a bundler definition from a configuration object. Required methods: `initialize`, `detectImports`, `bundle`, `execute`, `registerModule`. Optional: `resolveDependencies`, `cleanup`.
Usage [#usage]
```typescript
import { createRuntimeClient, fromMemoryFS } from '@taucad/runtime';
import { replicad } from '@taucad/runtime/kernels';
import { esbuild } from '@taucad/runtime/bundler';
const client = createRuntimeClient({
kernels: [replicad()],
bundlers: [esbuild()],
fileSystem: fromMemoryFS(),
});
```
Related [#related]
* [Configure the Bundler](../guides/bundler-configuration)
* [Plugin System](../concepts/plugin-system)