esbuild
Extremely fast bundler and minifier written in Go, exposing build, transform, and watch APIs to JavaScript.
Official Documentation ↗v0.2x. Check the official docs for the latest API surface.Installation
npm install --save-exact esbuildpnpm add -D esbuildMethods
No methods match this filter.
Extremely fast bundler and minifier written in Go, exposing build, transform, and watch APIs to JavaScript.
Overview
esbuild is a bundler built around a parallelized Go core, delivering bundling, transpilation, and minification at speeds that change how often you can build. Its API surface is small: build for bundling, transform for single-string conversion, and context for watch and rebuild loops.
The plugin system hooks resolve and load, which powers virtual modules and integration with frameworks. Target environments, format, and minification are plain options, and because transforms are deterministic and fast, esbuild sits inside Vite and many meta-frameworks as their lower layer.
Core Methods
The most frequently used entry points, with signatures and runnable examples:
esbuild.build— Bundles entry points with dependency resolution, code splitting, and output writing to disk.esbuild.transform— Converts a single source string, TypeScript or JSX, without resolving imports or touching the filesystem.esbuild.context— Creates a long-lived build for watch mode, manual rebuilds, and serve, replacing the old watch API.plugins— Hook package resolution and file loading to implement virtual modules, environment injection, or custom loaders.
Usage Notes
- Pin the exact version: the 0.x line has occasional breaking changes between minors.
- Keep a single shared options object between dev context and prod build so outputs cannot drift.
- Externalize server-only packages with external when bundling for edge or browser targets.
Common Pitfalls
- Missing type errors surprise teams: tsc must run separately because esbuild never checks types.
- Plugins run synchronously per file with filters; sloppy regexes across all namespaces slow every build.
- bundle: false leaves imports untouched, producing output that still needs a module runtime.
FAQ
- Does esbuild type-check TypeScript?
- No. esbuild strips types syntactically for speed and does not run the type checker. Run tsc --noEmit separately in CI so type errors still gate merges while esbuild handles emit.
- How do I use esbuild in development?
- Create a context and either watch for rebuild on change or use serve to serve output plus live reload. Production builds then reuse the same options without the context.
- Can I target different output formats from one config?
- Yes: call build once per format, or use out-extension and multiple entry points with splitting for ESM. Keep a base options object and spread it per target to avoid drift.
Report a problem with this API docOpens a pre-filled issue on GitHub.