From 7a87ff4b0950012ad0d85b05fe36b17e1ee2ee76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=A2=E7=BF=BC?= <659240788@qq.com> Date: Tue, 25 Apr 2023 20:51:37 +0800 Subject: [PATCH] feat(plugin-legacy): support file protocol (#8524) Co-authored-by: sapphi-red Co-authored-by: Bjorn Lu --- packages/plugin-legacy/src/snippets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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}};`