Skip to content

Commit

Permalink
fix(plugin-legacy): avoid executing blank dynamic import (#4767)
Browse files Browse the repository at this point in the history
Closes #4568
  • Loading branch information
nulladdict committed Sep 1, 2021
1 parent 1012367 commit de71408
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-legacy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const legacyEntryId = 'vite-legacy-entry'
const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`
const dynamicFallbackInlineCode = `!function(){try{new Function("m","return import(m)")}catch(o){console.warn("vite: loading legacy build because dynamic import is unsupported, syntax error above should be ignored");var e=document.getElementById("${legacyPolyfillId}"),n=document.createElement("script");n.src=e.src,n.onload=function(){${systemJSInlineCode}},document.body.appendChild(n)}}();`

const blankDynamicImport = `import('data:text/javascript;base64,Cg==');`
const forceDynamicImportUsage = `export function __vite_legacy_guard(){import('data:text/javascript,')};`

const legacyEnvVarMarker = `__VITE_IS_LEGACY__`

Expand Down Expand Up @@ -238,7 +238,7 @@ function viteLegacyPlugin(options = {}) {
const ms = new MagicString(raw)

if (genDynamicFallback && chunk.isEntry) {
ms.prepend(blankDynamicImport)
ms.prepend(forceDynamicImportUsage)
}

if (raw.includes(legacyEnvVarMarker)) {
Expand Down

0 comments on commit de71408

Please sign in to comment.