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(plugin-legacy): improve default polyfill #8312

Merged
merged 3 commits into from
Jun 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
const facadeToLegacyPolyfillMap = new Map()
const facadeToModernPolyfillMap = new Map()
const modernPolyfills = new Set<string>()
// System JS relies on the Promise interface. It needs to be polyfilled for IE 11. (array.iterator is mandatory for supporting Promise.all)
const DEFAULT_LEGACY_POLYFILL = [
'core-js/modules/es.promise',
'core-js/modules/es.array.iterator'
]
const legacyPolyfills = new Set(DEFAULT_LEGACY_POLYFILL)
const legacyPolyfills = new Set<string>()

if (Array.isArray(options.modernPolyfills)) {
options.modernPolyfills.forEach((i) => {
Expand Down Expand Up @@ -148,11 +143,13 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {

// legacy bundle
if (legacyPolyfills.size || genDynamicFallback) {
if (!legacyPolyfills.has('es.promise')) {
// check if the target needs Promise polyfill because SystemJS relies
// on it
await detectPolyfills(`Promise.resolve()`, targets, legacyPolyfills)
}
// check if the target needs Promise polyfill because SystemJS relies on it
// https://github.com/systemjs/systemjs#ie11-support
await detectPolyfills(
`Promise.resolve(); Promise.all();`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding Promise.all() makes legacyPolyfills to include core-js/modules/es.array.iterator.js.

targets,
legacyPolyfills
)
Comment on lines +146 to +152
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polyfills other than core-js/modules/es.promise may be added for Promise.resolve/Promise.all so the if condition is not correct.


isDebug &&
console.log(
Expand Down