diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 64a8fdce9b2826..b5d1b9ee1b4bf7 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -512,8 +512,9 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { if (specifier !== undefined) { // skip external / data uri if ( - (isExternalUrl(specifier) && !specifier.startsWith('file://')) || - isDataUrl(specifier) + ((isExternalUrl(specifier) && !specifier.startsWith('file://')) || + isDataUrl(specifier)) && + !matchAlias(specifier) ) { return } diff --git a/playground/alias/__tests__/alias.spec.ts b/playground/alias/__tests__/alias.spec.ts index 7c77e57a7497df..f8bbea6474b379 100644 --- a/playground/alias/__tests__/alias.spec.ts +++ b/playground/alias/__tests__/alias.spec.ts @@ -46,6 +46,12 @@ test('aliased module', async () => { ) }) +test('url conflict alias', async () => { + expect(await page.textContent('.url-conflict')).toMatch( + '[success] url conflict alias', + ) +}) + test('custom resolver', async () => { expect(await page.textContent('.custom-resolver')).toMatch( '[success] alias to custom-resolver path', diff --git a/playground/alias/dir/url_conflict.js b/playground/alias/dir/url_conflict.js new file mode 100644 index 00000000000000..a46c1beba908f5 --- /dev/null +++ b/playground/alias/dir/url_conflict.js @@ -0,0 +1 @@ +export const msg = `[success] url conflict alias` diff --git a/playground/alias/index.html b/playground/alias/index.html index f292ea5c8ad07a..58d51f680751b0 100644 --- a/playground/alias/index.html +++ b/playground/alias/index.html @@ -5,6 +5,7 @@