Next-generation ES module bundler
Clone or download
Latest commit b9e786d Sep 22, 2018
Permalink
Failed to load latest commit information.
.circleci chore: move to circleci (#2390) Aug 13, 2018
.github typo Aug 30, 2018
.vscode add vscode debugger settings (#2276) Jun 20, 2018
bin/src Throw better error messages for parse errors in non-JS files (#2466) Sep 21, 2018
browser Switch to rollup-plugin-typescript2 (#2460) Sep 16, 2018
scripts Fix perf script (#2433) Sep 16, 2018
src fix: plugin name in template string (#2470) Sep 21, 2018
test fix: plugin name in template string (#2470) Sep 21, 2018
typings Add memory perf metric along with time metrics (#2370) Aug 3, 2018
.editorconfig Add editorconfig file Dec 22, 2017
.eslintignore Remove unnecessary dependency, update dependencies, fix linting of te… Aug 5, 2018
.eslintrc.json use rollup.watch in CLI, update tests, various other things Aug 10, 2017
.gitattributes Force unix linebreaks Feb 14, 2016
.gitignore Switch back to official typescript plugin (#2465) Sep 19, 2018
.prettierrc set line length to 100 Mar 7, 2018
CHANGELOG.md Update changelog Sep 22, 2018
CODE_OF_CONDUCT.md docs: create code of conduct (#2388) Aug 9, 2018
CONTRIBUTING.md Fix some links Feb 1, 2018
LICENSE.md update LICENSE Jul 13, 2017
README.md readme updates Jun 14, 2018
appveyor.yml chore: move to circleci (#2390) Aug 13, 2018
package-lock.json 0.66.2 Sep 21, 2018
package.json 0.66.2 Sep 21, 2018
rollup.config.js Switch back to official typescript plugin (#2465) Sep 19, 2018
tsconfig.json Update rollup dependencies and make watcher more stable (#2297) Jun 23, 2018
tslint.json Remove unnecessary dependency, update dependencies, fix linting of te… Aug 5, 2018

README.md

Rollup

build status npm version install size license dependency status Join the chat at https://gitter.im/rollup/rollup

Overview

Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library or application. It uses the standardized ES module format for code, instead of previous idiosyncratic solutions such as CommonJS and AMD. ES modules let you freely and seamlessly combine the most useful individual functions from your favorite libraries. Rollup can optimize ES modules for faster native loading in modern browsers, or output a legacy module format allowing ES module workflows today.

Quick Start Guide

Install with npm install --global rollup. Rollup can be used either through a command line interface with an optional configuration file, or else through its JavaScript API. Run rollup --help to see the available options and parameters. The starter project templates, rollup-starter-lib and rollup-starter-app, demonstrate common configuration options, and more detailed instructions are available throughout the user guide.

Commands

These commands assume the entry point to your application is named main.js, and that you'd like all imports compiled into a single file named bundle.js.

For browsers:

# compile to a <script> containing a self-executing function
$ rollup main.js --format iife --name "myBundle" --file bundle.js

For Node.js:

# compile to a CommonJS module
$ rollup main.js --format cjs --file bundle.js

For both browsers and Node.js:

# UMD format requires a bundle name
$ rollup main.js --format umd --name "myBundle" --file bundle.js

Why

Developing software is usually easier if you break your project into smaller separate pieces, since that often removes unexpected interactions and dramatically reduces the complexity of the problems you'll need to solve, and simply writing smaller projects in the first place isn't necessarily the answer. Unfortunately, JavaScript has not historically included this capability as a core feature in the language.

This finally changed with ES modules support in JavaScript, which provides a syntax for importing and exporting functions and data so they can be shared between separate scripts. The specification is now implemented in all major browsers and in Node.js behind the --experimental-modules flag for ".mjs" files. Rollup allows you to write your code using this module system, either outputting optimized ES modules for use in these native environments, or compiling it back down to existing supported formats such as CommonJS modules, AMD modules, and IIFE-style scripts. This means that you get to write future-proof code, and you also get the tremendous benefits of...

Tree Shaking

In addition to enabling the use of ES modules, Rollup also statically analyzes and optimizes the code you are importing, and will exclude anything that isn't actually used. This allows you to build on top of existing tools and modules without adding extra dependencies or bloating the size of your project.

For example, with CommonJS, the entire tool or library must be imported.

// import the entire utils object with CommonJS
var utils = require( 'utils' );
var query = 'Rollup';
// use the ajax method of the utils object
utils.ajax( 'https://api.example.com?search=' + query ).then( handleResponse );

But with ES modules, instead of importing the whole utils object, we can just import the one ajax function we need:

// import the ajax function with an ES import statement
import { ajax } from 'utils';
var query = 'Rollup';
// call the ajax function
ajax( 'https://api.example.com?search=' + query ).then( handleResponse );

Because Rollup includes the bare minimum, it results in lighter, faster, and less complicated libraries and applications. Since this approach is based on explicit import and export statements, it is vastly more effective than simply running an automated minifier to detect unused variables in the compiled output code.

Compatibility

Importing CommonJS

Rollup can import existing CommonJS modules through a plugin.

Publishing ES Modules

To make sure your ES modules are immediately usable by tools that work with CommonJS such as Node.js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the main property in your package.json file. If your package.json file also has a module field, ES-module-aware tools like Rollup and webpack 2 will import the ES module version directly.

Links

Contributors

This project exists thanks to all the people who contribute. [Contribute].

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

MIT