principlejavascriptModerate
esbuild: why it is fast and where it cannot replace Babel
Viewed 0 times
esbuild speedesbuild vs babelesbuild limitationstypescript stripgo bundler
Problem
Teams assume esbuild is a full Babel replacement and remove Babel from their pipeline, then discover that certain transforms (decorators, custom Babel plugins, some macro libraries) break silently.
Solution
Use esbuild for transpilation and bundling where speed matters (Vite, tsup default). Keep Babel only for transforms esbuild does not support: legacy decorators (stage 2), babel-plugin-macros, custom AST transforms.
// esbuild handles:
// - TypeScript stripping (no type-checking)
// - JSX transform
// - ES2020+ downleveling
// - Code splitting, tree shaking
// esbuild does NOT handle:
// - TypeScript type-checking (use tsc --noEmit separately)
// - Stage 2 decorators (use @swc/core or Babel)
// - babel-plugin-styled-components source maps
// - Any plugin that needs full AST mutation
// esbuild handles:
// - TypeScript stripping (no type-checking)
// - JSX transform
// - ES2020+ downleveling
// - Code splitting, tree shaking
// esbuild does NOT handle:
// - TypeScript type-checking (use tsc --noEmit separately)
// - Stage 2 decorators (use @swc/core or Babel)
// - babel-plugin-styled-components source maps
// - Any plugin that needs full AST mutation
Why
esbuild is written in Go and uses a hand-written parser that avoids full AST-level plugin APIs by design. This is what makes it 10-100x faster than JS-based tools, but it also makes an extensible plugin ecosystem impossible for AST transforms.
Gotchas
- esbuild strips TypeScript types without checking them — always run tsc --noEmit in CI
- esbuild's tree shaking is statement-level, not as aggressive as Rollup's
- Target option in esbuild controls syntax lowering, not polyfills — add polyfills separately
- Using esbuild's 'bundle' mode changes resolution to node_modules; without it only files are transformed
Context
Evaluating or migrating from Babel to esbuild as the primary transpiler
Revisions (0)
No revisions yet.