diff --git a/packages/plugin-legacy/src/snippets.ts b/packages/plugin-legacy/src/snippets.ts index a07b9b7da99d79..664bc89bdb8452 100644 --- a/packages/plugin-legacy/src/snippets.ts +++ b/packages/plugin-legacy/src/snippets.ts @@ -9,7 +9,7 @@ export const systemJSInlineCode = `System.import(document.getElementById('${lega const detectModernBrowserVarName = '__vite_is_modern_browser' export const detectModernBrowserDetector = 'import.meta.url;import("_").catch(()=>1);async function* g(){};' -export const detectModernBrowserCode = `${detectModernBrowserDetector}window.${detectModernBrowserVarName}=true;` +export const detectModernBrowserCode = `${detectModernBrowserDetector}if(location.protocol!="file:"){window.${detectModernBrowserVarName}=true}` export const dynamicFallbackInlineCode = `!function(){if(window.${detectModernBrowserVarName})return;console.warn("vite: loading legacy chunks, syntax error above and the same error below should be ignored");var e=document.getElementById("${legacyPolyfillId}"),n=document.createElement("script");n.src=e.src,n.onload=function(){${systemJSInlineCode}},document.body.appendChild(n)}();` export const modernChunkLegacyGuard = `export function __vite_legacy_guard(){${detectModernBrowserDetector}};`