rollup

Bundle JavaScript modules for distribution

TLDR

Bundle JavaScript
$ rollup [main.js] --file [bundle.js]
Use configuration file
$ rollup -c
Output format
$ rollup [main.js] -o [bundle.js] -f [es]
Watch for changes
$ rollup -c --watch
Generate sourcemap
$ rollup [main.js] -o [bundle.js] -m
Bundle with a specific plugin
$ rollup [main.js] -o [bundle.js] -p [node-resolve]

SYNOPSIS

rollup [options] input

DESCRIPTION

rollup is a JavaScript module bundler focused on ES modules. It compiles small pieces of code into larger bundles, with excellent tree-shaking to eliminate unused code.The tool produces efficient bundles for libraries and applications, supporting multiple output formats.

PARAMETERS

-c file, --config file

Configuration file.
-o file, --file file
Output file.
-f fmt, --format fmt
Output format (es, cjs, umd, iife, amd, system).
-n name, --name name
UMD/IIFE global name.
-m, --sourcemap
Generate sourcemap.
-w, --watch
Watch mode.
-p plugin, --plugin plugin
Use plugin.
-d dir, --dir dir
Output directory (for code splitting).
-e modules, --external modules
Comma-separated list of external module IDs.
-g pairs, --globals pairs
Comma-separated global:module pairs for UMD/IIFE.
--no-treeshake
Disable tree shaking.

CONFIGURATION

rollup.config.js / rollup.config.mjs

Project-level configuration file defining input entry points, output formats, plugins, and external dependencies. Loaded automatically with -c or by specifying a path.

INSTALL

sudo zypper install rollup
brew install rollup

CAVEATS

Configuration needed for complex projects. Plugin ecosystem essential. CommonJS needs plugin. Build time can be slow for large projects.

HISTORY

Rollup was created by Rich Harris in 2015. It pioneered ES module bundling with tree-shaking, influencing later bundlers. Harris also created Svelte.

SEE ALSO

webpack(1), esbuild(1), vite(1), parcel(1)