Bundling by default. Unlike esbuild, Bun always bundles by default. That’s why the
--bundle flag doesn’t appear in Bun examples. To transpile each file individually, use Bun.Transpiler.It’s just a bundler. Unlike esbuild, Bun’s bundler does not include a built-in dev server or file watcher. It’s just a bundler. The bundler is designed to be used with
Bun.serve and other runtime APIs to achieve the same effect. As such, all HTTP/file-watching related options are not applicable.Performance
With a performance-first API and heavily optimized Zig-based JS/TS parser, Bun’s bundler is 1.75x faster than esbuild on esbuild’s three.js benchmark.Bundle 10 copies of three.js from scratch with source maps and minification
Why migrate?
Here are some reasons you might want to migrate from esbuild to Bun’s bundler:Speed
Bun’s bundler is significantly faster than esbuild, especially for large projects. The Zig-based implementation and careful optimizations make builds complete faster.Native features
Bun includes native support for:- TypeScript and JSX: No configuration needed
- CSS bundling: Built-in CSS processing with modern features
- HTML processing: Bundle complete web applications
- Macros: Run code at build time
- Framework features: React Fast Refresh, server components
Unified toolchain
Bun provides a complete JavaScript runtime and toolkit:- Bundler
- Runtime
- Test runner
- Package manager
Modern defaults
Bun uses modern defaults:- ESM by default
- Modern JavaScript syntax
- Fast native loaders for common file types
CLI API
Both Bun and esbuild provide command-line interfaces.--minify don’t accept arguments. Other flags with arguments like --outdir <path> accept arguments; these flags can be written as --outdir out or --outdir=out. Some flags like --define can be specified multiple times: --define foo=bar --define bar=baz.
Additional flags
JavaScript API
Plugin API
Bun’s plugin API is similar to esbuild’s but not identical. Both useonLoad and onResolve hooks, but the exact API differs:
esbuild
Bun
- Bun requires explicit
loaderspecification inonLoad - Bun supports additional lifecycle hooks:
onStart,onEnd,onBeforeParse - Bun’s plugin system is shared between runtime and bundler
Migration checklist
-
Update your build script
- Change
esbuildtobun buildin CLI commands - Change
esbuild.build()toBun.build()in JavaScript
- Change
-
Remove
--bundleflag- Bun bundles by default
- Add
--no-bundleif you need transpilation only
-
Update loader syntax
- Change
--loader:.svg=textto--loader .svg:text
- Change
-
Update naming options
assetNames→naming.assetchunkNames→naming.chunkentryNames→naming.entry
-
Update platform option
--platform→--target
-
Check unsupported features
- Remove
--serve(useBun.serveinstead) - Remove
--target(syntax downleveling not supported) - Remove
--injectif used
- Remove
-
Update plugins
- Review plugin API differences
- Add explicit
loadertoonLoadreturns - Test plugin behavior
-
Test your build
- Run the new build command
- Verify output files
- Test in browsers/environments
Example migration
Before (esbuild)
package.json
After (Bun)
package.json
Getting help
If you encounter issues during migration:- Check the Bun documentation
- Search GitHub issues
- Ask in the Bun Discord
- File a bug report if you find a problem