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

refactor: improve the polyfill importing logic of modern mode #5513

Merged
merged 6 commits into from May 25, 2020

Conversation

sodatea
Copy link
Member

@sodatea sodatea commented May 22, 2020

It is both a bugfix and refactoring.

Fixes #5507.

Fixed:

  • Should also apply the polyfills option to the modern mode target

Improved:

  • Should provide the exact version of core-js instead of a vague 3 to @babel/preset-env, making the polyfills more accurate and up-to-date
  • By calculating the intersection of modern browsers and browserslist targets, we may come to a much narrower range of browsers, thus greatly reducing the final bundle size. It may even yield a better result than the bugfixes option of @babel/preset-env.

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Underlying tools
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

Other information:

…ven targets

partially fixed the problem mentioned in #5507
fixes another issue mentioned in #5507

Note now core-js is listed as an optional peer depedency.
TODO: should remove it from depdencies in the next major.
…-specified targets

We don't need to target browsers that users don't need, even if it is
a browser that supports `script type="module"`.

With this change, with the default target of "last 2 versions", we no
longer has to deal with the obsolete versions of evergreen browsers that
comes with all kinds of bugs.
This further improves the modern build bundle size. Maybe even better
than [the `bugfixes` option of `preset-env`](https://babeljs.io/docs/en/babel-preset-env#bugfixes)
@sodatea
Copy link
Member Author

sodatea commented May 22, 2020

Note:
If we pass the target { esmodules: true, browsers: ['last 2 versions'] } to @babel/preset-env, it interprets the target as a union of the 2 sets of browsers, which is not ideal IMO.

@sodatea
Copy link
Member Author

sodatea commented May 22, 2020

It's basically the scenario described here: babel/babel#8809

@sodatea sodatea merged commit 91ca0b1 into dev May 25, 2020
@sodatea sodatea deleted the fix-modern-mode-custom-polyfills branch May 25, 2020 02:15
sapphi-red added a commit to traPtitech/traQ_S-UI that referenced this pull request May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

edge modern Promise.allSettled polyfill
1 participant