Programmatic Bundler API in Bun
From the Bun cheat sheet ยท Bundler ยท verified Jul 2026
Programmatic Bundler API
Use Bun.build() in code with plugins and advanced options
typescript
const result = await Bun.build({
entrypoints: ["./src/index.ts"],
outdir: "./dist",
target: "browser",
minify: true,
});
if (!result.success) {
console.error(result.logs);
}๐ก Bun.build() returns artifacts with path, size, and hash โ useful for build pipelines
โก Plugins use the same API as esbuild plugins โ most esbuild plugins work in Bun
๐ Use env: "inline" to replace process.env references with actual values at build time
๐ข Check result.success and result.logs to catch build errors programmatically
buildpluginsapi