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): build.ssr is set during dev, fix #9134 #9187

Merged
merged 1 commit into from
Jul 18, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export async function optimizeDeps(
): Promise<DepOptimizationMetadata> {
const log = asCommand ? config.logger.info : debug

const ssr = !!config.build.ssr
const ssr = config.command === 'build' && !!config.build.ssr

const cachedMetadata = loadCachedDepOptimizationMetadata(
config,
Expand Down Expand Up @@ -446,7 +446,8 @@ export function depsLogString(qualifiedIds: string[]): string {
export async function runOptimizeDeps(
resolvedConfig: ResolvedConfig,
depsInfo: Record<string, OptimizedDepInfo>,
ssr: boolean = !!resolvedConfig.build.ssr
ssr: boolean = resolvedConfig.command === 'build' &&
!!resolvedConfig.build.ssr
): Promise<DepOptimizationResult> {
const isBuild = resolvedConfig.command === 'build'
const config: ResolvedConfig = {
Expand Down Expand Up @@ -748,7 +749,7 @@ export function depsFromOptimizedDepInfo(
export function getOptimizedDepPath(
id: string,
config: ResolvedConfig,
ssr: boolean = !!config.build.ssr
ssr: boolean
): string {
return normalizePath(
path.resolve(getDepsCacheDir(config, ssr), flattenId(id) + '.js')
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/optimizer/optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function initDepsOptimizer(
server?: ViteDevServer
): Promise<void> {
// Non Dev SSR Optimizer
const ssr = !!config.build.ssr
const ssr = config.command === 'build' && !!config.build.ssr
if (!getDepsOptimizer(config, ssr)) {
await createDepsOptimizer(config, server)
}
Expand Down Expand Up @@ -95,7 +95,7 @@ async function createDepsOptimizer(
): Promise<void> {
const { logger } = config
const isBuild = config.command === 'build'
const ssr = !!config.build.ssr // safe as Dev SSR don't use this optimizer
const ssr = isBuild && !!config.build.ssr // safe as Dev SSR don't use this optimizer

const sessionTimestamp = Date.now().toString()

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function resolvePlugins(
wasmFallbackPlugin(),
definePlugin(config),
cssPostPlugin(config),
config.build.ssr ? ssrRequireHookPlugin(config) : null,
isBuild && config.build.ssr ? ssrRequireHookPlugin(config) : null,
isBuild && buildHtmlPlugin(config),
workerImportMetaUrlPlugin(config),
...buildPlugins.pre,
Expand Down