Esta página se muestra en inglés. Una traducción al español está en curso.
SkillsApr 12, 2026·3 min de lectura

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.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
step-1.md
Comando de instalación directa
npx -y tokrepo@latest install e9883503-366b-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

TL;DR
Rollup compiles ES modules into optimized bundles with best-in-class tree-shaking, built for library authors.
§01

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.

§02

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.

§03

How to use

  1. Install Rollup: npm install -D rollup
  2. Create a config file rollup.config.js
  3. Bundle: npx rollup -c
  4. Use watch mode during development: npx rollup -c --watch
§04

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
§05

Related on TokRepo

§06

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

Preguntas frecuentes

How is Rollup different from webpack?+

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.

Why does Vite use Rollup?+

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.

Does Rollup support TypeScript?+

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.

What is tree-shaking?+

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.

Can Rollup output multiple formats?+

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.

Referencias (3)

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados