From 382d14d74c114ac703deacb9f1a9f61af78e402e Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Tue, 24 May 2022 23:07:00 +0900 Subject: [PATCH 1/3] refactor(plugin-legacy): add .js to DEFAULT_LEGACY_POLYFILL This will dedupe imports and debug output. (does not affect output though) --- packages/plugin-legacy/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index ed2c4a24820a61..5fd6bffb9c6c89 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -63,8 +63,8 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { const modernPolyfills = new Set() // 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' + 'core-js/modules/es.promise.js', + 'core-js/modules/es.array.iterator.js' ] const legacyPolyfills = new Set(DEFAULT_LEGACY_POLYFILL) From 8b4ae5c0ae0b4b48dc33d42fa5153e1daf59c8a7 Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Tue, 24 May 2022 23:10:51 +0900 Subject: [PATCH 2/3] refactor(plugin-legacy): remove polyfill detection --- packages/plugin-legacy/src/index.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index 5fd6bffb9c6c89..a6ef55c8511ff3 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -148,12 +148,6 @@ 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) - } - isDebug && console.log( `[@vitejs/plugin-legacy] legacy polyfills:`, From 9dd9a81cd098d5b56df8187cf1efac1408c9607e Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Wed, 25 May 2022 01:19:29 +0900 Subject: [PATCH 3/3] refactor(plugin-legacy): only inject polyfill for systemjs if needed --- packages/plugin-legacy/src/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index a6ef55c8511ff3..70bb3c5e5ddeeb 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -61,12 +61,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { const facadeToLegacyPolyfillMap = new Map() const facadeToModernPolyfillMap = new Map() const modernPolyfills = new Set() - // 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.js', - 'core-js/modules/es.array.iterator.js' - ] - const legacyPolyfills = new Set(DEFAULT_LEGACY_POLYFILL) + const legacyPolyfills = new Set() if (Array.isArray(options.modernPolyfills)) { options.modernPolyfills.forEach((i) => { @@ -148,6 +143,14 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] { // legacy bundle if (legacyPolyfills.size || genDynamicFallback) { + // 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();`, + targets, + legacyPolyfills + ) + isDebug && console.log( `[@vitejs/plugin-legacy] legacy polyfills:`,