From a0336bd5197bb4427251be4c975e30fb596c658f Mon Sep 17 00:00:00 2001 From: asivery <82324156+asivery@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:10:47 +0100 Subject: [PATCH] fix: consider URLs with any protocol to be external (#17369) Co-authored-by: patak-dev Co-authored-by: bluwy Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> --- packages/vite/src/node/plugins/importAnalysis.ts | 5 ++++- packages/vite/src/node/utils.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index a7a77968ea5550..8281c1bcbedd17 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -509,7 +509,10 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { // If resolvable, let's resolve it if (specifier !== undefined) { // skip external / data uri - if (isExternalUrl(specifier) || isDataUrl(specifier)) { + if ( + (isExternalUrl(specifier) && !specifier.startsWith('file://')) || + isDataUrl(specifier) + ) { return } // skip ssr externals and builtins diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index fa50fc882e566e..8b234f20c8e316 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -262,7 +262,7 @@ export function isSameFileUri(file1: string, file2: string): boolean { ) } -export const externalRE = /^(https?:)?\/\// +export const externalRE = /^([a-z]+:)?\/\// export const isExternalUrl = (url: string): boolean => externalRE.test(url) export const dataUrlRE = /^\s*data:/i