Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dev SSR dep optimization + respect optimizeDeps.include #11123

Merged
merged 2 commits into from Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/vite/src/node/optimizer/index.ts
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
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