Skip to content

[P2] esbuild code splitting / esbuild 代码分割 #3226

@doudouOUC

Description

@doudouOUC

Priority: P2
Category: performance, cli
Parent: #3011
Depends on: Lazy load heavy optional dependencies sub-issue (creates the import() split points)

Problem / 问题

Single monolithic dist/cli.js bundle forces V8 to parse all code at startup. V8 gives up lazy parsing for very large files, making startup slower. All optional subsystems (OTel, LSP, code highlighting, channels) are inlined.

单体 dist/cli.js 迫使 V8 在启动时解析所有代码。超大文件导致 V8 放弃懒解析。所有可选子系统被内联。

Proposed Solution / 方案

Enable esbuild code splitting:

  1. Prior sub-issue's import() calls automatically create split points
  2. Configure esbuild with splitting: true, format: 'esm'
  3. Verify chunks load correctly from dist/ directory

Expected split chunks:

  • Main entry (cli.js) — core runtime only
  • chunk-otel.js — OpenTelemetry SDK + exporters
  • chunk-highlight.js — highlight.js/lowlight
  • chunk-lsp.js — LSP subsystem
  • chunk-channels.js — channel packages

Reference: Claude Code uses Bun bundle with automatic code splitting via dynamic import().

Acceptance Criteria / 验收标准

  • dist/cli.js reduced in size (main entry only)
  • Optional chunks load on demand
  • npm pack includes all chunks
  • All modes (interactive, non-interactive, channel) work correctly

Metadata

Metadata

Assignees

Labels

category/cliCommand line interface and interactioncategory/performancePerformance and optimizationpriority/P2Medium - Moderately impactful, noticeable problem

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions