Basic Usage
Transpiler Options
Loader
Specify the input format:Target
Set the output JavaScript version:"browser"- Modern browsers (ES2020+)"bun"- Bun runtime (latest features)"node"- Node.js compatibility
JSX Configuration
Classic JSX Transform
Automatic JSX Runtime
TSConfig
Load TypeScript configuration:Macros
Enable compile-time macros:Transform Methods
Synchronous Transform
Fastest for small inputs:Transform with Source Map
Scan Imports
Extract import statements:TypeScript Features
Type Stripping
Types are removed:Enums
Decorators
Namespace
JSX Features
JSX Elements
JSX Fragments
JSX Spread
Modern JavaScript
Optional Chaining
Nullish Coalescing
Class Fields
Top-Level Await
Source Maps
Inline Source Map
External Source Map
Scan for Dependencies
Import Analysis
Export Analysis
Performance
Benchmarks
Bun’s transpiler is extremely fast:- Bun: ~0.5ms per file
- esbuild: ~1-2ms per file
- tsc: ~50-100ms per file
- Babel: ~100-200ms per file
Optimization Tips
-
Reuse transpiler instance
-
Disable source maps when not needed
-
Use specific loaders
Comparison with Other Tools
vs TypeScript Compiler (tsc)
- Bun: Type stripping only (no type checking)
- tsc: Full type checking + transpilation
- Speed: Bun is ~100x faster
- Use case: Bun for development, tsc for CI
vs esbuild
- Bun: Built-in, no dependencies
- esbuild: Separate tool
- Speed: Similar (both very fast)
- Features: Bun has tighter integration
vs Babel
- Bun: TypeScript + JSX built-in
- Babel: Requires plugins
- Speed: Bun is ~200x faster
- Flexibility: Babel has more transforms
vs SWC
- Bun: Written in Zig
- SWC: Written in Rust
- Speed: Similar performance
- Integration: Bun has deeper runtime integration