Overview
Rollup.js is an open-source JavaScript module bundler launched in 2015, specifically engineered to compile small, optimized bundles from ECMAScript modules (ESM). It is widely adopted for packaging JavaScript libraries and applications where minimal bundle size and high performance are critical. Rollup achieves this efficiency through a technique called tree-shaking, which statically analyzes code imports and exports to eliminate unused code, resulting in smaller output files that load and execute faster in browsers and Node.js environments. This contrasts with some other bundlers that might include more boilerplate or unused modules in the final output.
The core design principle of Rollup is to leverage the native module system of JavaScript (ESM) directly. This allows it to create a single, flat bundle that avoids the overhead of common module formats like CommonJS or AMD, which often wrap modules in additional function calls. This direct approach contributes to faster execution and a more compact output, making Rollup a preferred choice for library authors who prioritize distribution size and runtime performance. For instance, popular frameworks like Vue.js and Svelte utilize Rollup for their production builds to deliver highly optimized bundles to their users.
Rollup is particularly well-suited for scenarios where the primary goal is to produce a JavaScript library or component that will be integrated into other projects. Its focus on generating pure ES module output allows consumers to benefit from native module loading and further tree-shaking by their own bundlers. While capable of bundling applications, its strengths are most evident in library development due to its aggressive optimization and adherence to the ES module specification. Developers choose Rollup when they need fine-grained control over their bundle output and seek to minimize dependencies and unnecessary code.
In terms of developer experience, Rollup provides a command-line interface and a robust plugin system, enabling extensibility for tasks such as transpilation (e.g., Babel integration), minification, and handling non-JavaScript assets. Its configuration is often considered more straightforward than some alternatives for basic bundling tasks, though it can become complex with extensive plugin usage. The project maintains comprehensive documentation, including an introduction to Rollup.js and a detailed plugin development guide, which supports developers in extending its capabilities.
Key features
- Tree-shaking (Dead Code Elimination): Rollup employs static analysis to identify and remove unused code from the final bundle, leading to smaller file sizes and improved load times. This is a core strength for optimizing JavaScript libraries and applications by ensuring only necessary code is included.
- ECMAScript Module (ESM) Support: It natively understands and processes ES Modules, allowing for efficient bundling that preserves the module graph and enables advanced optimizations. This direct use of ESM contributes to more performant and smaller bundles compared to formats that introduce additional runtime overhead.
- Code Splitting: Rollup can split code into multiple chunks that can be loaded on demand, which helps reduce the initial load time of web applications by only fetching the necessary code. This feature is crucial for larger applications to improve perceived performance.
- Plugin System: Offers an extensible plugin API that allows developers to customize the bundling process. Plugins can handle various tasks, including transpiling code (e.g., with Babel), minifying output, resolving third-party modules, and processing non-JavaScript assets like CSS or images.
- Output Formats: Supports outputting bundles in various formats, including ES Module (ESM), CommonJS (CJS), Asynchronous Module Definition (AMD), IIFE (Immediately Invoked Function Expression), and UMD (Universal Module Definition), providing flexibility for different deployment targets.
- Configuration via JavaScript: Rollup configurations are written in JavaScript, allowing for programmatic control and dynamic adjustments to the bundling process based on environment or specific requirements.
Pricing
Rollup.js is a free and open-source project. Its core bundler and official plugins are available under the MIT License.
| Service Level | Features | Pricing (as of May 2026) |
|---|---|---|
| Core Bundler | JavaScript module bundling, tree-shaking, multiple output formats, plugin support | Free and open source |
| Official Plugins | Extend Rollup functionality (e.g., Babel integration, commonjs support, node resolution) | Free and open source |
Common integrations
- Babel: Integrate with
@rollup/plugin-babelto transpile modern JavaScript syntax (ESNext) into backward-compatible versions for broader browser support. The Rollup Babel Plugin documentation provides configuration details. - CommonJS Modules: Use
@rollup/plugin-commonjsto convert CommonJS modules into ES Modules, allowing them to be processed by Rollup's tree-shaking algorithm. Refer to the CommonJS Plugin documentation for usage. - Node.js Resolution: The
@rollup/plugin-node-resolveenables Rollup to locate third-party modules innode_modules, similar to how Node.js resolves modules. Configuration is available in the Node Resolve Plugin documentation. - TypeScript: Integrate with
@rollup/plugin-typescriptto compile TypeScript files into JavaScript during the bundling process. The TypeScript Plugin documentation details setup and options. - PostCSS: Use
rollup-plugin-postcssto process CSS with PostCSS, enabling features like autoprefixing, SASS, or Less compilation. Details can be found on the PostCSS integrations page. - Minification: Integrate with plugins like
rollup-plugin-terseror@rollup/plugin-uglifyto minify the final JavaScript bundle, reducing its size for production deployment.
Alternatives
- webpack: A highly configurable module bundler primarily used for complex single-page applications, offering extensive loaders and plugins for various asset types and advanced optimization features like hot module replacement. webpack's core concepts provide further insight.
- Vite: A build tool that aims to provide a faster and leaner development experience for modern web projects, leveraging native ES Modules in development and esbuild for production bundling. The Vite guide outlines its approach.
- esbuild: A JavaScript bundler and minifier written in Go, known for its extremely fast build times, often used for development builds or in conjunction with other tools. esbuild's getting started guide highlights its performance.
- Parcel: A zero-configuration web application bundler that emphasizes ease of use and developer experience, providing out-of-the-box support for many asset types without extensive setup.
- Gulp.js / Grunt.js: Task runners that can automate various development workflows, including bundling, though they typically rely on separate tools for the actual JavaScript module bundling process itself.
Getting started
To begin using Rollup.js, you typically install it as a development dependency in your project. The following steps demonstrate a basic setup for bundling a simple JavaScript module.
First, create a new project directory and initialize npm:
mkdir my-rollup-project
cd my-rollup-project
npm init -y
Next, install Rollup as a development dependency:
npm install --save-dev rollup
Create an input file, src/main.js:
// src/main.js
import { greet } from './utils.js';
function runApp() {
console.log(greet('Rollup User'));
}
runApp();
Create a utility file, src/utils.js:
// src/utils.js
export function greet(name) {
return `Hello, ${name}! Welcome to Rollup.js.`;
}
Now, create a Rollup configuration file, rollup.config.js, in the root of your project:
// 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 bundle the application:
npx rollup -c
This command will create a file named dist/bundle.js containing your bundled application. You can then include this bundle.js file in an HTML page or use it as an ES module in another project.
// dist/bundle.js (example output)
function greet(name) {
return `Hello, ${name}! Welcome to Rollup.js.`;
}
function runApp() {
console.log(greet('Rollup User'));
}
runApp();
Notice how Rollup has tree-shaken the code and flattened the modules into a single, optimized file without extra module wrappers. For more advanced configurations and plugin usage, consult the official Rollup.js documentation.