Skip to content

Commit

Permalink
refactor(plugin-legacy): improve default polyfill (#8312)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Jun 1, 2022
1 parent 01b5ebf commit 4370d91
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,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 @@ -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(
Expand Down

0 comments on commit 4370d91

Please sign in to comment.