Rollup — Next-Generation ES Module Bundler for Libraries
Rollup is an ES module bundler designed for building JavaScript libraries and packages. It produces clean, efficient output with excellent tree-shaking, making it the preferred choice for library authors and the production bundler used by Vite.
Installation agent prête
Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.
npx -y tokrepo@latest install e9883503-366b-11f1-9bc6-00163e2b0d79 --target codexÀ exécuter après confirmation du plan en dry-run.
What it is
Rollup is an ES module bundler designed specifically for building JavaScript libraries and packages. Unlike webpack, which targets applications, Rollup produces clean, readable output that uses ES modules natively. It performs aggressive tree-shaking by statically analyzing imports and exports to eliminate dead code.
Rollup is the de facto standard for building JavaScript libraries. React, Vue, Svelte, D3, Three.js, and hundreds of other major libraries use Rollup. It also serves as the production bundler inside Vite.
How it saves time or tokens
Rollup's tree-shaking removes unused code at build time, producing smaller bundles than alternatives. For library authors, this means end users download less code. The clean ESM output is easier to debug than webpack's runtime wrapper. Code splitting lets you ship only what each consumer imports.
How to use
- Install Rollup:
npm install -D rollup - Create a config file
rollup.config.js - Bundle:
npx rollup -c - Use watch mode during development:
npx rollup -c --watch
Example
// rollup.config.js
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
export default {
input: 'src/index.js',
output: [
{ file: 'dist/bundle.esm.js', format: 'esm' },
{ file: 'dist/bundle.cjs.js', format: 'cjs' },
{ file: 'dist/bundle.min.js', format: 'iife', name: 'MyLib', plugins: [terser()] }
],
plugins: [resolve(), commonjs()]
};
# Bundle with config
npx rollup -c
# Quick one-liner without config
npx rollup src/index.js --file dist/bundle.js --format esm
Related on TokRepo
- AI Tools for Coding -- Developer tools for building and bundling
- Featured Workflows -- Top-rated workflows on TokRepo
Common pitfalls
- CommonJS modules require the @rollup/plugin-commonjs plugin; without it,
require()calls fail silently - Circular dependencies produce warnings and can cause runtime errors; refactor to break cycles
- The default output format is ESM; specify
format: 'cjs'explicitly if your consumers need CommonJS
Questions fréquentes
Rollup is optimized for libraries and produces clean ES module output with aggressive tree-shaking. Webpack is designed for applications with features like hot module replacement, dev server, and code splitting for lazy loading. Most library authors choose Rollup; most app developers choose webpack or Vite.
Vite uses esbuild for development (fast transforms) and Rollup for production builds (mature plugin ecosystem and reliable tree-shaking). This combination gives developers fast dev feedback and optimized production output.
Yes, through plugins. Use @rollup/plugin-typescript or rollup-plugin-ts to compile TypeScript during the bundle step. Rollup itself only handles JavaScript, but the plugin ecosystem covers TypeScript, CSS, JSON, and more.
Tree-shaking is the process of removing unused code from the final bundle. Rollup analyzes static ES module imports and exports to determine which functions and variables are actually used, then eliminates everything else.
Yes. A single rollup.config.js can output ESM, CommonJS, UMD, IIFE, and AMD formats simultaneously. This is standard practice for library authors who need to support different module systems.
Sources citées (3)
- Rollup GitHub— Rollup is the ES module bundler used by Vite for production builds
- Rollup Documentation— Tree-shaking via static analysis of ES module imports
- Vite Documentation— Vite uses Rollup for production bundling
En lien sur TokRepo
Fil de discussion
Actifs similaires
Prisma — Next-Generation ORM for Node.js & TypeScript
Prisma is a next-generation ORM for Node.js and TypeScript supporting PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB, and CockroachDB. Type-safe database access with auto-generated client and intuitive schema language.
Rolldown — Rust-Powered JavaScript Bundler and the Future of Vite
Rolldown is a Rust-based Rollup-compatible bundler built by the Vite team. It replaces esbuild + Rollup in Vite with a single fast bundler, bringing dramatic speed improvements while keeping the plugin API developers already know.
Dendrite — Next-Generation Matrix Homeserver in Go
Dendrite is a second-generation Matrix homeserver written in Go, designed for resource efficiency and easy deployment while supporting the full Matrix federation protocol.
Next.js — The Full-Stack React Framework for the Web
Next.js is the most popular React framework for building full-stack web applications. It provides server-side rendering, static generation, API routes, file-based routing, and React Server Components — making React production-ready out of the box.