Skip to content

Commit abf7844

Browse files
committed
feat: support aliasing to external url
1 parent 0f4e70e commit abf7844

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/vite/src/node/plugins/importAnalysis.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
185185
// if the resolved id is not a valid browser import specifier,
186186
// prefix it to make it valid. We will strip this before feeding it
187187
// back into the transform pipeline
188-
if (!url.startsWith('.') && !url.startsWith('/')) {
188+
if (
189+
!url.startsWith('.') &&
190+
!url.startsWith('/') &&
191+
!isExternalUrl(url)
192+
) {
189193
url =
190194
VALID_ID_PREFIX + resolved.id.replace('\0', NULL_BYTE_PLACEHOLDER)
191195
}

packages/vite/src/node/server/pluginContainer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { FSWatcher } from 'chokidar'
5757
import {
5858
createDebugger,
5959
generateCodeFrame,
60+
isExternalUrl,
6061
normalizePath,
6162
numberToPos,
6263
prettifyUrl,
@@ -459,7 +460,7 @@ export async function createPluginContainer(
459460
}
460461

461462
if (id) {
462-
partial.id = normalizePath(id)
463+
partial.id = isExternalUrl(id) ? id : normalizePath(id)
463464
return partial as PartialResolvedId
464465
} else {
465466
return null

0 commit comments

Comments
 (0)