generator-babel-boilerplate icon indicating copy to clipboard operation
generator-babel-boilerplate copied to clipboard

Add Rollup option to the CLI

Open jamesplease opened this issue 8 years ago • 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

jamesplease avatar Feb 20 '16 01:02 jamesplease

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.

paulfalgout avatar Feb 28 '16 07:02 paulfalgout

Gonna try to do this this week.

Note to self: this PR, https://github.com/marionettejs/backbone.radio/pull/247 , can be used as a reference. Thanks for doing the hard work, @megawac!

jamesplease avatar May 10 '16 16:05 jamesplease

Note to self: here's the rollup API stuff that's relevant to me: https://github.com/rollup/rollup/wiki/JavaScript-API

jamesplease avatar May 11 '16 18:05 jamesplease

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.

jamesplease avatar May 12 '16 05:05 jamesplease

Another thing to consider is that Rollup lacks incremental builds.

https://github.com/rollup/rollup/issues/191

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.

jamesplease avatar May 12 '16 05:05 jamesplease

I converted a lib of mine to Rollup to see how it'd go. That work is here:

https://github.com/jmeas/bizniz.js/pull/10

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.

jamesplease avatar May 12 '16 05:05 jamesplease

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

paulfalgout avatar May 14 '16 02:05 paulfalgout

Thanks for the feedback, @paulfalgout ! I agree with a lot of that :v: Definitely leaning toward Rollup atm.

jamesplease avatar May 14 '16 04:05 jamesplease

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).

megawac avatar May 14 '16 17:05 megawac

saw this today: https://github.com/kriasoft/babel-starter-kit

paulfalgout avatar May 15 '16 03:05 paulfalgout

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?

jamesplease avatar May 15 '16 17:05 jamesplease

Yeah, or as one of the options (in a select menu) for yo babel-boilerplate

megawac avatar May 15 '16 19:05 megawac

Cool, cool. I like that idea. What do you think, @paulfalgout ?

jamesplease avatar May 15 '16 19:05 jamesplease