What esbuild Does
- Bundling — merge modules into one file
- TypeScript — strip types (no type check)
- JSX — transform JSX to JS
- Minification — tree-shake + compress
- Tree shaking — remove unused exports
- Source maps — for debugging
- Plugin API — custom loaders and resolvers
- Splitting — code splitting for dynamic imports
- Watch mode — incremental rebuilds
Architecture
Written in Go for parallelism (Go is 10x faster than JS for this kind of work + perfect concurrency). Parses, transforms, and prints all in one pass without intermediate AST serialization. No babel, no multiple plugins stacking up overhead.
Self-Hosting
Bundled as a binary via npm. Ships in your build pipeline.
Key Features
- 10-100x faster than webpack/Rollup
- TypeScript + JSX out of the box
- Tree shaking
- Minification
- Source maps
- CSS bundling (basic)
- Plugin API
- Incremental watch mode
- WASM build available
Comparison
| Tool | Speed | Features | Plugins |
|---|---|---|---|
| esbuild | Fastest | Minimal | Limited |
| Rollup | Medium | Mature | Huge ecosystem |
| webpack | Slow | Most features | Huge ecosystem |
| Rolldown | Very fast | WIP | Rollup-compatible |
| Rspack | Very fast | webpack-compatible | webpack ecosystem |
常见问题 FAQ
Q: 为什么这么快? A: Go 写的(原生并行)+ 零中间 AST + 单遍解析+转换+打印 + 精简 plugin API。Evan 写过详细的 architecture doc。
Q: 生产环境能用吗?
A: 能。Figma、Vite、Bun 都在生产用。但不做类型检查,需配合 tsc --noEmit 单独跑。
Q: 和 Vite 的关系? A: Vite 开发模式用 esbuild 做依赖预打包;生产构建用 Rollup(因 plugin 生态更成熟)。
来源与致谢 Sources
- Docs: https://esbuild.github.io
- GitHub: https://github.com/evanw/esbuild
- License: MIT