Skip to content

Commit

Permalink
fix(dev): build.ssr is set during dev, fix #9134 (#9187)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev authored Jul 18, 2022
1 parent c5f2dc7 commit 99b0e67
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
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

0 comments on commit 99b0e67

Please sign in to comment.