Skip to content

Commit

Permalink
fix(optimizer): ensure esbuild use vite-resolved entries
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 23, 2021
1 parent 69d8d01 commit bdb9b3c
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions packages/vite/src/node/optimizer/esbuildDepPlugin.ts
Expand Up @@ -32,14 +32,20 @@ export function esbuildDepPlugin(
}
)

// record transitive deps
build.onResolve({ filter: /^[\w@]/ }, ({ path: id }) => {
if (!(id in qualified) && !isBuiltin(id)) {
// ensure esbuild uses our resolved entires of optimized deps in all
// cases
if (id in qualified) {
return {
path: path.resolve(qualified[id])
}
}
// record transitive deps
if (!isBuiltin(id)) {
const deepMatch = id.match(deepImportRE)
const pkgId = deepMatch ? deepMatch[1] || deepMatch[2] : id
transitiveOptimized[pkgId] = true
}
return null
})

// redirect node-builtins to empty module for browser
Expand Down Expand Up @@ -75,21 +81,6 @@ export function esbuildDepPlugin(
}
}
)

if (config.dedupe) {
build.onResolve(
{
filter: new RegExp(`^(${config.dedupe.join('|')})$`)
},
({ path: id }) => {
if (id in qualified) {
return {
path: path.resolve(qualified[id])
}
}
}
)
}
}
}
}

0 comments on commit bdb9b3c

Please sign in to comment.