Skip to main content
Bun includes a fast transpiler that converts TypeScript, JSX, and modern JavaScript to browser-compatible JavaScript. It’s written in Zig and optimized for performance.

Basic Usage

Transpiler Options

Loader

Specify the input format:

Target

Set the output JavaScript version:
Targets:
  • "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:
Or provide inline:

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:
Comparison:
  • Bun: ~0.5ms per file
  • esbuild: ~1-2ms per file
  • tsc: ~50-100ms per file
  • Babel: ~100-200ms per file

Optimization Tips

  1. Reuse transpiler instance
  2. Disable source maps when not needed
  3. 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

Use Cases

Build Tools

Hot Module Replacement

Testing

Documentation

Advanced Configuration

Custom Defines

Path Resolution

External Packages

Error Handling