Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On automatic modern polyfill detection, remove features that are already supported by the ones support ESModules #9839

Closed
4 tasks done
Tal500 opened this issue Aug 25, 2022 · 1 comment

Comments

@Tal500
Copy link
Contributor

Tal500 commented Aug 25, 2022

Description

In vite plugin legacy docs, it says the following on the option modernpolyfills:

Note it is not recommended to use the true value (which uses auto-detection) because core-js@3 is very aggressive in polyfill inclusions due to all the bleeding edge features it supports. Even when targeting native ESM support, it injects 15kb of polyfills!

Now I wonder - why can't this plugin somehow, will take the generated polyfill list, and substruct from this list every polyfill that isn't required for any modern browser - meaning every feature such that every targeted browser either doesn't fully support ESModules, or already supports this specific polyfill feature.

I believe this can reduce the modern polyfill output drastically.

It kinda reminding issue #6922, but tries to solve the huge polyfill output problem from another direction.

Suggested solution

Use some library that can tell us for every feature in the polyfill, which browsers already support this feature, then filter this browser lists to the target browser list, and then check whether there is some browser in which the minimal version that the polyfill is already supported is bigger than the version of this browser with a full ESModule support.

If the answer is "yes" - add this polyfill (to modern). Otherwise - don't bundle this polyfill.

Alternative

No response

Additional context

No response

Validations

@bluwy
Copy link
Member

bluwy commented Aug 28, 2022

This is already the case I believe, just that corejs's browser compat table is more aggresive, e.g. if an API that works perfectly fine in browser A, but has this one edgecase bug, it will get polyfilled. We can't simply subtract it out as it means we need to build our own compat table, and it's HUGE. Another alternative would be doing something like #2433 (comment) too, and you can subtract those out yourself. Closing as this likely won't be implemented.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Aug 28, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Sep 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants