While searching to generate and use as few javascript bytes as possible in the name of performance, I hit a wall. I use stage-3 and es2015 presets, and so I need Polyfill and helpers.
It is worth mentioning that I do not collect all my files, I lazily upload them as needed with RequireJS. I was hoping to link Polyfill and helpers to my main.js
My question is:
Is it possible to create a custom assembly of Polyfill and external helpers that contain only those ES features that I actually use?
1. Polyfill:
Polyfill is nearly 90 kB and seems to include Promises, iterators, generators, reflection, a map / set, and the entire ES2015 standard library. Most of this, I really don't need. What if I use only iterators and generators? I would like to shave all possible bytes from 90kb. Polyfill seems to be all or nothing. Of course, I could achieve this manually by simply linking only those parts of the js kernel that I need, but then I would need to maintain a list of the exact ES functions that I use, I would like to avoid this if possible. And I don't know where to start with the custom regenerator that it uses for Reflect.
2. External assistants:
Since I do not want my external helpers to be duplicated in several files, I went looking for a way to create 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, and not just the ones I need, in the same situation as with polyfill. Inside, Babylon probably knows what functions I use because it generates code, for example, babelHelpers.createClass.
source share