Files
tsbundle/readme.plan.md

4.0 KiB

tsbundle Rolldown Integration Plan

Command to reread CLAUDE.md: cat ~/.claude/CLAUDE.md

Objective

Add Rolldown as an optional bundler to tsbundle while keeping esbuild as the default bundler. This allows users to experiment with Rolldown using --bundler=rolldown flag.

Current State

  • tsbundle currently only uses esbuild despite having interfaces for multiple bundlers
  • The bundler selection logic exists but always returns esbuild
  • mod_rollup and mod_parcel directories exist but are empty
  • Recent commits disabled splitting and tree-shaking in esbuild due to issues

Implementation Tasks

Phase 1: Core Infrastructure

  • Update ts/interfaces/index.ts to include 'rolldown' in bundler union type
  • Fix getBundlerPath() in ts/tsbundle.class.tsbundle.ts to properly route bundlers
  • Remove hardcoded bundler: 'esbuild' from transportOptions (line 26)
  • Add rolldown dependency to package.json: "rolldown": "^1.0.0-beta.18"

Phase 2: CLI Support

  • Check if ts/tsbundle.cli.ts already parses --bundler option
  • Ensure default bundler is 'esbuild' when not specified
  • Verify CLI passes bundler option correctly to TsBundle class

Phase 3: Rolldown Module Implementation

  • Create ts/mod_rolldown/ directory
  • Create ts/mod_rolldown/plugins.ts:
    export * from '../plugins.js';
    import { rolldown } from 'rolldown';
    export { rolldown }
    
  • Create ts/mod_rolldown/index.child.ts with:
    • TsBundleProcess class
    • getAliases() method for tsconfig path resolution
    • buildTest() method (sourcemaps, no minification)
    • buildProduction() method (minified output)
    • run() function to read transportOptions and execute

Phase 4: Feature Parity

  • Implement TypeScript compilation via rolldown
  • Ensure source map generation works
  • Support tsconfig path aliases
  • Match esbuild's ESM output format
  • Implement minification for production builds
  • Handle bundle: true behavior

Phase 5: Testing

  • Test default behavior (should use esbuild)
  • Test --bundler=esbuild explicit selection
  • Test --bundler=rolldown selection
  • Compare output between esbuild and rolldown
  • Verify all existing tests pass with both bundlers

Technical Specifications

Rolldown Configuration Mapping

esbuild option rolldown equivalent
bundle: true bundle: true
sourcemap: true sourcemap: true
format: 'esm' format: 'es'
target: 'es2022' (use default, no direct equivalent)
minify: true minify: true
entryPoints input
outfile output.file
tsconfig resolve.tsconfigFilename
alias resolve.alias

CLI Usage

# Default (uses esbuild)
tsbundle

# Use rolldown
tsbundle --bundler=rolldown

# Production build with rolldown
tsbundle --production --bundler=rolldown

Risks and Mitigation

  1. Rolldown is beta - Keep esbuild as default, mark rolldown as experimental
  2. API differences - Abstract common interface, handle bundler-specific logic
  3. Missing features - Document any limitations in README
  4. Breaking changes - None, as esbuild remains default

Success Criteria

  • Can build with esbuild (default behavior unchanged)
  • Can build with rolldown via --bundler flag
  • Both bundlers produce working ESM output
  • Source maps work with both bundlers
  • TypeScript compilation works with both
  • All existing tests pass

Implementation Status

COMPLETED - Rolldown has been successfully integrated as an optional bundler.

Test Results:

  • esbuild (default): Working correctly, 2.2K minified
  • rolldown: Working correctly, 1.5K minified (better compression!)
  • Both bundlers support all required features
  • CLI properly routes to selected bundler
  • Production and test modes work for both

Future Considerations

  • Once Rolldown reaches v1.0.0 stable, consider making it default
  • Implement rollup and parcel modules using same pattern
  • Add performance benchmarks comparing bundlers
  • Consider adding --watch mode support