Skip to content

Commit

Permalink
fix: fix web_modules resolving for build
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 6, 2020
1 parent e01e26d commit fc75323
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/node/buildPluginResolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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('/')) {
Expand All @@ -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
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/node/serverPluginModuleResolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const moduleResolvePlugin: Plugin = ({ root, app }) => {
})
}

async function resolveWebModule(
export async function resolveWebModule(
root: string,
id: string
): Promise<string | undefined> {
Expand Down

0 comments on commit fc75323

Please sign in to comment.