During my search for generating and serving as few bytes of javascript as possible in the name of performance, I've struck a wall. I am using the stage-3 and es2015 presets, and thus I need the Polyfill and Helpers.
Worth mentioning is that I'm not bundling all my files, I'm lazy-loading them as needed with RequireJS. I was hoping to bundle the polyfill and helpers with my main.js.
My question is:
Is it possible to generate a custom build of the polyfill and external-helpers, containing only the ES features I actually use?
1. Polyfill:
The polyfill is almost 90kb, and seems to include Promises, Iterators, Generators, Reflect, Map/Set and the entire ES2015 standard library. Most of it, I don't actually need. What if I'm only using Iterators and Generators? I'd like to shave off every possible byte from that 90kb. It seems the polyfill is an all or nothing situation.
I could achieve this manually of course, by just bundling only the parts of core-js I need, but then I'd need to maintain a list of which exact ES features I use, I'd like to avoid that if possible. And I would not know where to start with the customized regenerator it uses for Reflect.
2. External Helpers:
Since I don't want my external-helpers to be duplicated across multiple files, I went looking for a way to generate them. The documentation seems sparse, but I found this:
var code = require('./node_modules/babel-core/lib/tools/build-external-helpers')();
This gives me all the helpers that exist in babel, instead of just the ones I need, the same situation as with the polyfill. Internally, Babel probably knows which features I'm using, because it generates code like babelHelpers.createClass.