What Is Rollup? The JavaScript Module Bundler Explained
Rollup is a JavaScript bundler that excels at producing small, clean, tree-shaken output, making it a favorite for libraries and the engine behind Vite's production builds.
Rollup popularized tree-shaking, the practice of dropping code that is never used, by leaning on ES module static analysis. It produces lean bundles in multiple formats, which is why it is the go-to bundler for publishing libraries and the production bundler inside Vite.
What Rollup is
Rollup is a module bundler for JavaScript that takes ES modules and combines them into a single file or a small set of files. It outputs in several formats (ESM, CommonJS, UMD) so a library can ship for many consumers, and it is extended through a focused plugin API.
Tree-shaking and clean output
Because ES modules are statically analyzable, Rollup can determine which exports are actually used and exclude the rest, producing smaller bundles. It also tends to generate flat, readable output without the wrapper boilerplate heavier bundlers add, which matters when shipping a library others will inspect.
A config example
A library config emits multiple formats from one input.
export default {
input: "src/index.js",
output: [
{ file: "dist/lib.cjs", format: "cjs" },
{ file: "dist/lib.mjs", format: "es" }
]
};Role in CI/CD
In CI, Rollup builds the distributable artifacts for a library before publishing, or it runs as Vite's production bundler for apps. The build step is part of the release pipeline, often followed by a publish to npm. Caching node_modules and reusing build output where possible keeps these steps quick.
Alternatives
Webpack is more feature-rich for complex apps but heavier. esbuild is faster but produces less optimized output for library publishing. tsup wraps esbuild for simple library builds. Rollup remains the preferred choice when output quality and tree-shaking matter, as in library distribution.
Key takeaways
- Rollup produces small, clean, tree-shaken bundles in multiple formats.
- It is the standard for publishing libraries and powers Vite production builds.
- In CI it builds release artifacts, often just before publishing to npm.