Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

Sets up esbuild code splitting for ESM builds and implements dynamic imports to lazy-load optional features, reducing initial bundle size by ~17%.

esbuild configuration

  • Enable splitting: true with chunkNames: 'chunks/[name]-[hash]'
  • Switch from outfile to outdir + entryNames (required for splitting)
  • Add outExtension: { '.js': '.mjs' } for ESM output
  • Demo server kept as CJS with splitting: false

Dynamic imports

xterm.js core:

  • AccessibilityManager — loaded when screenReaderMode enabled (~16KB)
  • OverviewRulerRenderer — loaded when overviewRuler.width set (~11KB)

WebGL addon:

  • CustomGlyphDefinitions — loaded on first custom glyph render (~200KB)
let module: Promise<typeof import('./Module')> | undefined;
function loadModule(): Promise<typeof import('./Module')> {
  if (!module) module = import('./Module');
  return module;
}

loadModule().then(m => {
  if (/* conditions still valid */) {
    // use m.Export
  }
}).catch(() => { /* graceful fallback */ });

Bundle impact (dev build)

Bundle Before After
xterm.mjs 754KB 625KB
addon-webgl.mjs 454KB 244KB

Demo

  • Updated HTML to reference .mjs with type="module"
Original prompt

Set up code splitting for the esm build. Don't worry about breaking backwards compatibility or the single xterm.js bundle


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Set up code splitting for ESM build Set up code splitting for ESM build Jan 16, 2026
Copilot AI requested a review from Tyriar January 16, 2026 00:43
Copilot AI changed the title Set up code splitting for ESM build Enable code splitting for ESM build with dynamic imports for custom glyphs Jan 16, 2026
Copilot AI changed the title Enable code splitting for ESM build with dynamic imports for custom glyphs Enable ESM code splitting with dynamic imports for optional features Jan 16, 2026
@Tyriar Tyriar changed the title Enable ESM code splitting with dynamic imports for optional features Explore enabling ESM code splitting with dynamic imports for optional features Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants