Skip to content

feat: remove esbuild runtime dependency, use Vite's bundled rolldown/esbuild#12

Open
srsholmes wants to merge 1 commit into
mainfrom
fix/replace-esbuild-with-rolldown
Open

feat: remove esbuild runtime dependency, use Vite's bundled rolldown/esbuild#12
srsholmes wants to merge 1 commit into
mainfrom
fix/replace-esbuild-with-rolldown

Conversation

@srsholmes

Copy link
Copy Markdown
Owner

Summary

Removes esbuild from the plugin's runtime dependencies, reducing node_modules size for consumers. Vite 8+ already ships both Rolldown and esbuild — this PR leverages those instead of installing esbuild separately.

Changes

  • plugin.ts: Uses Rolldown's transformSync (from rolldown/utils, bundled with Vite 8) for JSX/Flow transformation. Rolldown is lazily loaded via buildStart to handle ESM dynamic import.
  • setup.ts: Resolves esbuild through Vite's dependency chain (createRequire(require.resolve('vite'))) instead of importing it directly. esbuild is still needed here because the pirates hook requires CJS output (format: 'cjs'), which Rolldown's transform API doesn't support.
  • package.json: Moved esbuild from dependenciesdevDependencies (only used by the build script, not shipped to consumers).

Why not full Rolldown?

Rolldown's transformSync is a syntax transformer (JSX, TypeScript) — it doesn't do module format conversion. The pirates hook in setup.ts intercepts require() calls and must output CJS, which requires esbuild's format: 'cjs'. Since esbuild ships with Vite anyway, resolving it through Vite's deps adds zero extra install weight.

Test plan

  • All 783 Vitest tests pass
  • All 164 Jest parity tests pass
  • Build succeeds (pnpm build)
  • esbuild is only in devDependencies, not dependencies

Fixes #3

🤖 Generated with Claude Code

…esbuild

- plugin.ts: use rolldown's transformSync (from Vite 8) for JSX/Flow transform
- setup.ts: resolve esbuild through vite's dependencies (no direct dep needed)
- Move esbuild from dependencies to devDependencies (only needed for build script)
- Consumers get slimmer node_modules since esbuild is no longer installed separately

Closes #3

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

const require = createRequire(import.meta.url);

// Resolve esbuild through vite's dependencies (no direct dependency needed)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems hacky and doesn't provide any benefits that I know of

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.

Consider switching from esbuild to Rolldown

2 participants