Add Rollup option to the CLI
Opened this issue · 13 comments
Should we move from Webpack to Rollup? Part of the motivation to Webpack originally had to do with lack of support in Rollup, though this now seems to largely be fixed.
@paulfalgout , I know you prefer Rollup. What are you thinking of the pros/cons?
@megawac, do you have any thoughts?
Another option would be/could be to switch back to Browserify.
This issue supersedes #310
Pros to switching to Rollup
- Straightforward to add header (ref #279)
- More readable output
- Output is smaller than webpack
- Tree shaking (when it works) is a plus
Cons to switching to Rollup
- babelrc weirdness when
gulpfile.babel.js
is used - barely does anything useful out of the box, vs. webpack's everything works out of the box approach. consequently, many many plugins are needed
- no incremental builds, but...this may not be particularly useful for small libs
The more I use rollup the more I like it for libraries.
It is focused on building libraries over other concerns, and it is pretty simplistic in what it is doing, which I think is good for libraries as well. It's also fast and lightweight, which for any library testing for multiple environments can be important. And while it isn't hugely important, the output is very readable and not littered with _interopRequireDefault
statements and other loader stuff.
And recently https://github.com/eventualbuddha/rollup-plugin-multi-entry was added so I think this could potentially be used for compiling the tests as well. Pretty ideal.
Gonna try to do this this week.
Note to self: this PR, marionettejs/backbone.radio#247 , can be used as a reference. Thanks for doing the hard work, @megawac!
Note to self: here's the rollup API stuff that's relevant to me: https://github.com/rollup/rollup/wiki/JavaScript-API
One difference between webpack and Rollup is that webpack tends to "Just Work" when it comes to importing, whereas Rollup tends to "Just Break." I'll prob. need to add a specific piece of information to the README that explains Rollup's out-of-the-box-behavior and its plugin ecosystem.
Another thing to consider is that Rollup lacks incremental builds.
There will be some early adoption costs for switching to Rollup at this stage, but so far it seems like things I'm OK dealing with for the time being.
I converted a lib of mine to Rollup to see how it'd go. That work is here:
Next up is upstreaming it to this boilerplate.
Another issue with Rollup is that the plugin for Babel excludes modules. This sucks for ES2015 gulpfiles, because it makes .babelrc
ONLY describe the Gulpfile. The library's Babel config will need to be specified in the Gulpfile directly. That's a real bummer.
I dunno that webpack does that much more out of the box that is useful to libraries. It does bake in some plugins.. consequently.. if we stick with uglify, webpack has it baked in and we could use that. but you still have to load a json loader and a babel loader. Most of the added plugins for rollup are to support browser testing.
Additionally if you're making very small libraries, webpack adds the loader.. where as rollup adds so very little.
Also rollup is much smaller than webpack.. not a huge deal, but if you're running tests across a matrix (as you might want to do for a library) that install time can add up quick.
I use webpack at the day job.. in many ways it is superior to rollup, but I think rollup is uniquely positioned for building libraries and I suspect that will only improve with time. I'm also not sure that the cons of rollup will be felt by the end user of the boilerplate
Thanks for the feedback, @paulfalgout ! I agree with a lot of that ✌️ Definitely leaning toward Rollup atm.
Both definitely have pros and cons. As you mentioned, its harder to goof up when bundling with webpack (except for accidentally bundling dependencies I suppose), whereas several issues can crop up with rollup. I think it probably makes sense to create a package.json and gulp configuration for both webpack and rollup and let the user select the bundler they prefer. Personally I will pretty much always go with rollup but webpack will generally be the more flexible option (and I'd say it should be the default).
saw this today: https://github.com/kriasoft/babel-starter-kit
Interesting idea to set it behind a flag, @megawac.
Do you think it should be a prompt, as in:
Would you like to use Webpack or Rollup?
or a flag, as in yo babel-boilerplate --rollup
?
Yeah, or as one of the options (in a select menu) for yo babel-boilerplate
Cool, cool. I like that idea. What do you think, @paulfalgout ?