Skip to content

Commit

Permalink
fix: Dev SSR dep optimization + respect optimizeDeps.include (#11123)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Nov 29, 2022
1 parent 14980a1 commit 515caa5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,8 @@ export async function addManuallyIncludedOptimizeDeps(
const resolve = config.createResolver({
asSrc: false,
scan: true,
ssrOptimizeCheck: ssr
ssrOptimizeCheck: ssr,
ssrConfig: config.ssr
})
for (const id of [...optimizeDepsInclude, ...extra]) {
// normalize 'foo >bar` as 'foo > bar' to prevent same id being added
Expand Down
9 changes: 6 additions & 3 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,11 @@ export function tryNodeResolve(
: OPTIMIZABLE_ENTRY_RE.test(resolved)

let exclude = depsOptimizer?.options.exclude
let include = depsOptimizer?.options.exclude
let include = depsOptimizer?.options.include
if (options.ssrOptimizeCheck) {
// we don't have the depsOptimizer
exclude = options.ssrConfig?.optimizeDeps?.exclude
include = options.ssrConfig?.optimizeDeps?.exclude
include = options.ssrConfig?.optimizeDeps?.include
}

const skipOptimization =
Expand All @@ -813,7 +813,10 @@ export function tryNodeResolve(
exclude?.includes(pkgId) ||
exclude?.includes(nestedPath) ||
SPECIAL_QUERY_RE.test(resolved) ||
(!isBuild && ssr) ||
// During dev SSR, we don't have a way to reload the module graph if
// a non-optimized dep is found. So we need to skip optimization here.
// The only optimized deps are the ones explicitly listed in the config.
(!options.ssrOptimizeCheck && !isBuild && ssr) ||
// Only optimize non-external CJS deps during SSR by default
(ssr &&
!isCJS &&
Expand Down

0 comments on commit 515caa5

Please sign in to comment.