From 4370d9123da20c586938753d9f606d84907334c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 1 Jun 2022 20:28:15 +0900 Subject: [PATCH] refactor(plugin-legacy): improve default polyfill (#8312) --- packages/plugin-legacy/src/index.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index ff6f30685e199a..05e276ca3b1ff8 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -63,12 +63,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', - 'core-js/modules/es.array.iterator' - ] - const legacyPolyfills = new Set(DEFAULT_LEGACY_POLYFILL) + const legacyPolyfills = new Set() if (Array.isArray(options.modernPolyfills)) { options.modernPolyfills.forEach((i) => { @@ -150,11 +145,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();`, + targets, + legacyPolyfills + ) isDebug && console.log(