You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
greenkeeperio-bot 55b62b42e6 chore(package): update sander to version 0.4.0 9 years ago
bin --no-indent cli option 9 years ago
browser fix travis error, hopefully 9 years ago
src Use declarations, regardless of whether they have statements or not 9 years ago
test Use declarations, regardless of whether they have statements or not 9 years ago
.babelrc remove sander dependency 9 years ago
.eslintrc Tabs! 9 years ago
.gitignore hack around lack of export on windows 9 years ago
.travis.yml replace iojs with node 4 in build matrix 9 years ago
CHANGELOG.md -> 0.19.2 9 years ago
LICENSE.md flesh out readme, add license 9 years ago
README.md Invalid LICENSE link 9 years ago
appveyor.yml update appveyor build matrix 9 years ago
gobblefile.js hack around lack of export on windows 9 years ago
package.json chore(package): update sander to version 0.4.0 9 years ago

README.md

Rollup

build status npm version license dependency status Coverage via Codecov

I roll up, I roll up, I roll up, Shawty I roll up

I roll up, I roll up, I roll upWiz Khalifa

Quickstart

Rollup can be used via a JavaScript API or a Command Line Interface. Install with npm install -g rollup and run rollup --help to get started.

Dive into the wiki when you're ready to learn more about Rollup and ES6 modules.

A next-generation ES6 module bundler

When you're developing software, it's much easier to break your library or application apart into separate pieces that you can work on separately. It's also very likely that you'll have dependencies on third party libraries. The result is lots of small files – but that's bad news for browsers, which get slowed down by having to make many requests. (It's also bad news for Node!)

The solution is to write your code as modules, and use a module bundler to concatenate everything into a single file. Browserify and Webpack are examples of module bundlers.

So far, so good, but there's a problem. When you include a library in your bundle...

var utils = require( 'utils' );

var query = 'Rollup';
utils.ajax( 'https://api.example.com?search=' + query ).then( handleResponse );

...you include the whole library, including lots of code you're not actually using.

ES6 modules solve this problem. Instead of importing the whole of utils, we can just import the ajax function we need:

import { ajax } from 'utils';

var query = 'Rollup';
ajax( 'https://api.example.com?search=' + query ).then( handleResponse );

Rollup statically analyses your code, and your dependencies, and includes the bare minimum in your bundle.

Shouldn't we be writing those utilities as small modules anyway?

Not always, no.

Don't minifiers already do this?

If you minify code with something like UglifyJS (and you should!) then some unused code will be removed:

(function () {
  function foo () {
    console.log( 'this function was included!' );
  }

  function bar () {
    console.log( 'this function was not' );
    baz();
  }

  function baz () {
    console.log( 'neither was this' );
  }

  foo();
})();

A minifier can detect that foo gets called, but that bar doesn't. When we remove bar, it turns out that we can also remove baz.

But because of the limitations of static analysis, and the dynamic nature of JavaScript, it can't do the same thing with code like this:

(function () {
  var obj = {
    foo: function () {
      console.log( 'this method was included!' );
    },

    bar: function () {
      console.log( 'so was this :-(' );
      this.baz();
    },

    baz: function () {
      console.log( 'and this :-(' );
    }
  };

  obj.foo();
})();

Unfortunately, traditional modules – CommonJS and AMD – result in code more like the second example than the first, making them next-to-impossible to optimise. Rather than excluding dead code, we should be including live code. That's only possible with ES6 modules.

What's the catch?

Most libraries that you depend on aren't written as ES6 modules, so Rollup can't work with them directly. (You can bundle your own app or library code with Rollup as a CommonJS module, then pass the result over to Webpack or Browserify, of course.)

You can help! It's possible to write libraries as ES6 modules while still making it easy for other developers to use your code as they already do, using the jsnext:main field in your package.json. You'll be writing your code in a more future-proof way, and helping to bring an end to the dark days of JavaScript package management.

See rollup-starter-project for inspiration on how to get started.

How does this compare to JSPM/SystemJS?

JSPM is awesome! It's a little different to this project though – it combines a repository with a package manager and a client-side module loader, as opposed to simply bundling modules. JSPM allows you to use any module format and even develop without a build step, so it's a great choice for creating applications. Rollup generates smaller bundles that don't use the complex SystemJS format, and so is a better choice for creating libraries. A future version of JSPM may use Rollup internally, so you'll get the best of both worlds.

License

Released under the MIT license.