scottcharlesworth / laravel-mix-polyfill

A Laravel Mix extension to include polyfills by using Babel, core-js, and regenerator-runtime
MIT License
50 stars 7 forks source link

Extract Polyfills #19

Closed MatteoMeil closed 4 years ago

MatteoMeil commented 4 years ago

Hi, I was wondering if there's a way to extract polyfills from bundled code.

This way the bundled file will be smaller and if I build polyfills for (e.g.) IE11 I can import polyfills.js only when I use that browser.

I.e.:

if (window.hasOwnProperty('ActiveXObject')) { // I'm using IE11 so append polyfills
    var head = document.getElementsByTagName('head')[0];
    var js = document.createElement("script");

    js.type = "application/javascript";
    js.src = "polyfills.js";

    head.appendChild(js);
}
scottcharlesworth commented 4 years ago

I don't think that's possible. This plug-in relies on core-js and babel, and I don't believe that functionality is available in the underlying libraries.

Normally the polyfills are very small, and because the plugin makes use of preset-env, it should only bundle the them when required.

What are your file sizes with and without polyfills?

MatteoMeil commented 4 years ago

The difference is not so big as I wrongly said in the original question (now edited): code with and without polyfills differs by 0.3MiB. It's not so big and can be ignored, I just wanted to know if there's the possibility