diff --git a/src/node/buildPluginResolve.ts b/src/node/buildPluginResolve.ts index d6bddae4084df5..7756ad25c9fe60 100644 --- a/src/node/buildPluginResolve.ts +++ b/src/node/buildPluginResolve.ts @@ -2,6 +2,7 @@ import { Plugin } from 'rollup' import { hmrClientId } from './serverPluginHmr' import { InternalResolver } from './resolver' import { resolveVue } from './vueResolver' +import { resolveWebModule } from './serverPluginModuleResolve' const debug = require('debug')('vite:build:resolve') @@ -13,7 +14,7 @@ export const createBuildResolvePlugin = ( ): Plugin => { return { name: 'vite:resolve', - resolveId(id: string) { + async resolveId(id: string) { if (id === hmrClientId) { return hmrClientId } else if (id.startsWith('/')) { @@ -33,12 +34,17 @@ export const createBuildResolvePlugin = ( external: true } } - } else { + } else if (!id.startsWith('.')) { const request = resolver.idToRequest(id) if (request) { const resolved = resolver.requestToFile(request) debug(id, `-->`, request, `--> `, resolved) return resolved + } else { + const webModulePath = await resolveWebModule(root, id) + if (webModulePath) { + return webModulePath + } } } }, diff --git a/src/node/serverPluginModuleResolve.ts b/src/node/serverPluginModuleResolve.ts index ec499e97ee7795..7fe25ca06cfeb7 100644 --- a/src/node/serverPluginModuleResolve.ts +++ b/src/node/serverPluginModuleResolve.ts @@ -92,7 +92,7 @@ export const moduleResolvePlugin: Plugin = ({ root, app }) => { }) } -async function resolveWebModule( +export async function resolveWebModule( root: string, id: string ): Promise {