0PricingLogin
React Academy · Lesson

Bundling with Rollup and tsup for Libraries

Configure Rollup or tsup to bundle React components with proper externalization of React and ReactDOM.

Why Not Use Vite for Libraries

Vite's default configuration is optimized for applications — it bundles everything, handles assets, and generates an index.html. For a component library, you need a different output: pure ESM/CJS JavaScript files with no runtime overhead, no bundled React, and proper TypeScript declarations. Vite library mode works but Rollup and tsup are more purpose-built for this.

Rollup: The Library Standard

Rollup has been the standard bundler for JavaScript libraries for years. It produces clean, efficient output with excellent tree-shaking and supports both ESM and CJS output formats. Rollup's scope hoisting eliminates module wrapper overhead, producing the smallest possible library bundles.

All lessons in this course

  1. Bundling with Rollup and tsup for Libraries
  2. ESM and CJS Dual Package Output
  3. Peer Dependencies and Tree Shaking
  4. Publishing to npm and Semantic Versioning
← Back to React Academy