Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Yet another module bundler #219
That's my point. Wouldn't it have been more efficient to dig in those codebases to implement the roll up concept code rather than trying to re-do already everything else that has already been done ?
Did you approach the browserify/webpack people to try to implement it ?
@Sinewyk it's a fair question, and one that we've been asked a few times, so I'll try and answer as thoroughly as possible so that this can serve as a reference.
Forget about the tree-shaking for a moment. Webpack and Browserify have their differences, but fundamentally they work off the same basic concept: wrap each module in a function, then wrap all those functions in a bundle that includes a module loader (Browserify's prelude.js or Webpack's
Rollup, by contrast, works similarly to es6-module-transpiler and Esperanto (both now deprecated in favour of Rollup). Rather than wrapping each module in its own function, all modules share a single scope. That makes ES6 module features like bindings and cycles trivial to implement; it also means that you're not paying the per-module cost of wrapping and continually re-declaring imports. The end result is far more compact, even in situations where tree-shaking wouldn't help because all the code is being used. (Here is Redux built with Webpack, here it is built with Rollup – minified and gzipped, the Rollup version is 14.5% smaller.)
Could you do that in Browserify and Webpack? I don't know, but my hunch is that it would be rather difficult – you're basically talking about a fundamental rethink of how they work. When I started writing Rollup, it was an experiment that I wasn't certain would succeed. It would have been rather bold of us to approach the maintainers of those tools to ask whether they'd consider tearing up their designs based on a hunch, so we chose instead to build a new, simple tool, focused on ES6 modules from the ground up (rather than being CommonJS-centric and supporting ES6 modules via transforms).
Webpack 2 will support tree-shaking
See here for the details. This is really fantastic news – Webpack has a large user base, and those users now have a powerful incentive to start using ES6 modules. Developments like this are significant in terms of moving the JS community away from legacy module formats, and I'm thrilled about it.
When should you use Webpack?
Webpack really shines if you're developing a complex application. I don't personally use it, because I'm not particularly keen on the way it encourages Webpack-specific idioms (such as overloading
It makes less sense if you're developing a library. The idea that a library should include a module loader (i.e.
I hope this goes some way towards explaining why this exists as a separate project. It doesn't exist as a criticism of Browserify (which I still use, occasionally) or Webpack, it exists because ES6 modules encourage a completely different approach to module bundling.
I'll close this issue, but happy to continue the discussion if necessary.
Thanks for detailed explanations. I only hope in the future we can merge some of these tools to avoid fragmenting even more the community.
I'll continue using webpack for applications (dev-server, code splitting), but I'll probably keep rollup in mind for libraries or simple applications where I don't need code splitting and can make due livereload stuff in another way.
nb: I'm only sligthly aware of webpack behavior for module bundling, I'm not proficient in saying how difficult it would be to merge both systems. Sorry if I was a condescending.
Not at all! It's a totally legitimate question that lots of people have asked
It's a pretty valid reason. A static module syntax (ES6) allows a wide range to advanced optimizations (see rollup), which would be difficult to integrate in a module bundler which allows mixing of ES6, CommonJS and AMD.
referenced this issue
Jul 10, 2016
@Rich-Harris thanks for the awesome post, would you care to elaborate this sentence?
I'm studying the downsides of