From 245e4af80c7859c16d23652f4265e678176e18b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=A2=E7=BF=BC?= <659240788@qq.com> Date: Fri, 10 Jun 2022 09:11:11 +0800 Subject: [PATCH 1/3] feat: support protocal file --- packages/plugin-legacy/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-legacy/src/index.ts b/packages/plugin-legacy/src/index.ts index 4aaab1aab2412d..3b72c744ad0dcb 100644 --- a/packages/plugin-legacy/src/index.ts +++ b/packages/plugin-legacy/src/index.ts @@ -40,7 +40,7 @@ const legacyEntryId = 'vite-legacy-entry' const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))` const detectModernBrowserVarName = '__vite_is_modern_browser' -const detectModernBrowserCode = `try{import.meta.url;import("_").catch(()=>1);}catch(e){}window.${detectModernBrowserVarName}=true;` +const detectModernBrowserCode = `try{import.meta.url;import("_").catch(()=>1);}catch(e){}if(window.location.protocol!=='file:'){window.${detectModernBrowserVarName}=true;}` const dynamicFallbackInlineCode = `!function(){if(window.${detectModernBrowserVarName})return;console.warn("vite: loading legacy build because dynamic import or import.meta.url 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 forceDynamicImportUsage = `export function __vite_legacy_guard(){import('data:text/javascript,')};` From 68d0276d994bcc936852b41f5cac6f044f4d87b2 Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Sat, 22 Apr 2023 20:17:40 +0900 Subject: [PATCH 2/3] chore: merge main From 23de288259086064a50470f64f15668762828053 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 17:46:48 +0800 Subject: [PATCH 3/3] Update packages/plugin-legacy/src/snippets.ts 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 72feb15d40f87d..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}if(window.location.protocol!="file:"){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}};`