SebastianS90 / webpack-polyfill-injector

Webpack plugin to automatically inject polyfills into your bundle without affecting modern browsers.
MIT License
82 stars 10 forks source link

Load polyfills that are not shipped in polyfill-service itself but referenced in the config.json file #2

Closed andyo729 closed 6 years ago

andyo729 commented 6 years ago

When I include support for Promise I get an error that the module cannot be found. I checked out polyfill-service and it appears that it is pointed to the wrong path. For example, Promise should go to: 'polyfill-service/polyfills/Promise/prototype/finally/polyfill'.

andyo729 commented 6 years ago

So, if I use Promise.prototype.finally in the polyfills array it appears to work. Might just be a matter of updating your docs.

SebastianS90 commented 6 years ago

You are right, there is a problem with the Promise polyfill. But simply using Promise.prototype.finally is not the correct solution, because that actually is a different polyfill (that one only contains the finally method and expects then and catch to be implemented by the browser. The Promise polyfill provides all three methods.)

Polyfill-service used to have a file at polyfill-service/polyfills/Promise/polyfill.js, this is the file which my injector package tries to load. But the file has been removed in later versions of polyfill-sevice. It looks like they now also reference polyfills from external packages, i.e. the Promise polyfill can actually be found at node_modules/yaku/dist/yaku.browser.global.min.js.

The solution for this issue here will be to edit this line such that:

I guess I'll have time to work on this next weekend.

SebastianS90 commented 6 years ago

There was actually a very simple solution to this problem: polyfill-service uses a postinstall script that compiles all polyfills to polyfill-service/polyfills/__dist/. So we can just take the files from there...