Skip to content

Commit

Permalink
fix(optimizer): let esbuild resolve transitive deps
Browse files Browse the repository at this point in the history
fix #2199
  • Loading branch information
yyx990803 committed Feb 24, 2021
1 parent e5324ca commit 0138ef3
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import path from 'path'
import { Loader, Plugin } from 'esbuild'
import { KNOWN_ASSET_TYPES } from '../constants'
import { ResolvedConfig } from '..'
import { isRunningWithYarnPnp, flattenId, normalizePath } from '../utils'
import {
isRunningWithYarnPnp,
flattenId,
normalizePath,
isBuiltin
} from '../utils'
import { browserExternalId } from '../plugins/resolve'
import { ExportsData } from '.'

Expand Down Expand Up @@ -97,18 +102,15 @@ export function esbuildDepPlugin(
return entry
}

// use vite resolver
const resolved = await resolve(id, importer)
if (resolved) {
if (resolved.startsWith(browserExternalId)) {
// externalize node built-ins
if (isBuiltin(id)) {
const resolved = await resolve(id, importer)
if (resolved && resolved.startsWith(browserExternalId)) {
return {
path: id,
namespace: 'browser-external'
}
}
return {
path: path.resolve(resolved)
}
}
}
)
Expand Down

0 comments on commit 0138ef3

Please sign in to comment.