Overview

Rollup.js is a module bundler for JavaScript that compiles small code modules into larger JavaScript files, such as libraries or applications. Its primary focus is on producing highly optimized, flat bundles, making it a common choice for developers creating reusable JavaScript libraries and frameworks. Rollup.js was first released in 2015 and pioneered the concept of tree-shaking, a form of dead code elimination that removes unused exports from the final bundle, resulting in smaller file sizes and improved load performance.

Unlike some other bundlers that might wrap modules in additional runtime code, Rollup.js aims to produce output that closely resembles the original source code, often referred to as a "flat bundle." This approach is particularly beneficial for libraries, as it can reduce overhead when integrated into other projects. It achieves this by directly concatenating modules and resolving dependencies statically during the build process, taking full advantage of the native ES module syntax for imports and exports as defined by MDN Web Docs. This makes Rollup.js well-suited for codebases that strictly adhere to ES module conventions.

Developers choose Rollup.js when the goal is to create highly performant and lightweight JavaScript packages. Its configuration, while sometimes more manual than other bundlers, provides fine-grained control over the bundling process. The project maintains an active plugin ecosystem, allowing extensibility for tasks like transpilation (e.g., Babel integration), minification, and handling various asset types. This flexibility, combined with its optimization capabilities, positions Rollup.js as a specialized tool for library authors and applications prioritizing minimal bundle size and native ES module output.

The core design philosophy of Rollup.js emphasizes generating efficient, production-ready code. It excels in scenarios where the final output needs to be a single, optimized JavaScript file, often without the need for a module loader at runtime. This contrasts with bundlers that might produce multiple chunks or rely on runtime module resolution. For projects targeting modern browsers and environments that fully support ES modules, Rollup.js can significantly simplify the deployment process and reduce the client-side footprint of JavaScript assets. Its use cases extend from small utility libraries to larger UI component frameworks, all benefiting from its focus on lean, well-structured output.

Key features

  • Tree-shaking (Dead Code Elimination): Rollup.js analyzes the import and export statements of ES modules to identify and remove any code that is not actively used, leading to smaller bundle sizes Rollup.js performance documentation.
  • ES Modules Native Output: It directly supports and outputs bundles using the native ES module syntax, making the generated code compatible with modern JavaScript environments and potentially more efficient for consumption by other ES module-aware tools.
  • Code Splitting: While focused on flat bundles, Rollup.js also supports code splitting to break large applications into smaller, asynchronously loaded chunks, optimizing initial load times for larger projects Rollup.js code splitting guide.
  • Plugin System: An extensible plugin API allows developers to integrate various tools and functionalities, such as transpiling newer JavaScript features with Babel, optimizing images, or handling CSS assets Rollup.js plugin development documentation.
  • Static Analysis: Rollup.js performs static analysis of code to determine dependencies and optimize modules without executing the code, contributing to predictable and robust builds.
  • Configuration Flexibility: Offers a programmatic JavaScript API and a configuration file (rollup.config.js) for detailed control over input, output formats, plugins, and other build options Rollup.js configuration options.
  • Multiple Output Formats: Supports various output formats, including ES module (ESM), CommonJS (CJS), Asynchronous Module Definition (AMD), IIFE (Immediately Invoked Function Expression), and UMD (Universal Module Definition), catering to different deployment targets.

Pricing

Rollup.js is a free and open-source project, distributed under the MIT License. There are no licensing fees, subscription costs, or commercial tiers associated with its use. The project is maintained by its community and individual contributors.

Rollup.js Product Pricing (as of May 2026)
Product/Service Pricing Model Details
Rollup.js Bundler Free and Open Source Full access to all features, plugins, and documentation. No commercial tiers or paid add-ons.

Common integrations

  • Babel: The @rollup/plugin-babel allows transpiling modern JavaScript syntax (like ES2015+) into compatible versions for older environments Rollup.js Babel plugin documentation.
  • TypeScript: Integration with TypeScript is handled via plugins like @rollup/plugin-typescript, enabling developers to write code in TypeScript and compile it to JavaScript during the build process Rollup.js TypeScript plugin.
  • PostCSS: The rollup-plugin-postcss allows processing CSS files with PostCSS, enabling features like autoprefixing, SASS/LESS compilation, and CSS minification within the Rollup build pipeline PostCSS Rollup plugin documentation.
  • Node.js: Rollup.js can bundle code for Node.js environments using the CommonJS output format and supports resolving Node.js modules via plugins like @rollup/plugin-node-resolve Rollup.js Node resolve plugin.
  • CommonJS Modules: The @rollup/plugin-commonjs allows Rollup.js to convert CommonJS modules into ES modules, making them compatible with Rollup's ES module-centric bundling approach Rollup.js CommonJS plugin.
  • Minification (Terser): Integration with Terser, a JavaScript parser and minifier, is common through plugins like rollup-plugin-terser to reduce file sizes for production deployments.

Alternatives

  • webpack: A widely used module bundler for JavaScript applications, known for its extensive features, module hot replacement, and ability to handle various asset types.
  • esbuild: A fast JavaScript bundler and minifier written in Go, emphasizing speed and efficiency for various build tasks.
  • Vite: A next-generation frontend tool that leverages native ES modules to provide a fast development experience with instant hot module replacement.
  • Astro: A modern static site builder that uses Rollup.js internally for its production builds, offering a solution for content-focused websites.

Getting started

To begin using Rollup.js, you typically install it via npm and then create a configuration file. The following example demonstrates how to bundle a simple JavaScript module.

First, install Rollup.js locally in your project:

npm install --save-dev rollup

Next, create an input file, src/main.js:

// src/main.js
import { add } from './utils.js';

console.log('Result:', add(5, 3));

And a utility file, src/utils.js:

// src/utils.js
export function add(a, b) {
  return a + b;
}

export function subtract(a, b) {
  return a - b;
}

Now, create a Rollup configuration file, rollup.config.js, in your project root:

// rollup.config.js
export default {
  input: 'src/main.js',
  output: {
    file: 'dist/bundle.js',
    format: 'es' // Output as an ES module
  }
};

Finally, run Rollup from your terminal to create the bundle:

npx rollup -c

This command will generate a dist/bundle.js file. Notice that the subtract function from utils.js will not be included in the bundle because Rollup's tree-shaking feature determines it's unused in main.js, demonstrating its optimization capabilities. The resulting bundle.js will contain only the necessary code:

// dist/bundle.js (simplified output)
function add(a, b) {
  return a + b;
}

console.log('Result:', add(5, 3));

This basic setup can be extended with plugins for more complex scenarios, such as transpiling with Babel or handling CSS, as outlined in the Rollup.js Introduction Guide.