Skip to content

Commit 12a4e7d

Browse files
authored
refactor(legacy): remove unneeded dynamic import var init code (#7759)
1 parent b89974a commit 12a4e7d

File tree

2 files changed

+0
-9
lines changed

2 files changed

+0
-9
lines changed

packages/plugin-legacy/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https
163163

164164
- `sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=`
165165
- `sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=`
166-
- `sha256-xYj09txJ9OsgySe5ommpqul6FiaJZRrwe3KTD7wbV6w=`
167166
- `sha256-4m6wOIrq/wFDmi9Xh3mFM2mwI4ik9n3TMgHk6xDtLxk=`
168167
- `sha256-uS7/g9fhQwNZS1f/MqYqqKv8y9hCu36IfX9XZB5L7YY=`
169168

packages/plugin-legacy/index.js

-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const legacyEntryId = 'vite-legacy-entry'
2020
const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`
2121

2222
const detectDynamicImportVarName = '__vite_is_dynamic_import_support'
23-
const detectDynamicImportVarInitCode = `var ${detectDynamicImportVarName}=false;`
2423
const detectDynamicImportCode = `try{import("_").catch(()=>1);}catch(e){}window.${detectDynamicImportVarName}=true;`
2524
const dynamicFallbackInlineCode = `!function(){if(window.${detectDynamicImportVarName})return;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)}();`
2625

@@ -437,12 +436,6 @@ function viteLegacyPlugin(options = {}) {
437436

438437
// 5. inject dynamic import fallback entry
439438
if (genDynamicFallback && legacyPolyfillFilename && legacyEntryFilename) {
440-
tags.push({
441-
tag: 'script',
442-
attrs: { type: 'module' },
443-
children: detectDynamicImportVarInitCode,
444-
injectTo: 'head'
445-
})
446439
tags.push({
447440
tag: 'script',
448441
attrs: { type: 'module' },
@@ -714,7 +707,6 @@ viteLegacyPlugin.default = viteLegacyPlugin
714707
viteLegacyPlugin.cspHashes = [
715708
createHash('sha256').update(safari10NoModuleFix).digest('base64'),
716709
createHash('sha256').update(systemJSInlineCode).digest('base64'),
717-
createHash('sha256').update(detectDynamicImportVarInitCode).digest('base64'),
718710
createHash('sha256').update(detectDynamicImportCode).digest('base64'),
719711
createHash('sha256').update(dynamicFallbackInlineCode).digest('base64')
720712
]

0 commit comments

Comments
 (0)