Skip to content

Commit

Permalink
fix(ssr): set ssr.target: 'webworker' defaults as fallback (#18827)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Nov 29, 2024
1 parent 2250ffa commit b39e696
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
26 changes: 9 additions & 17 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,6 @@ export function resolveBuildEnvironmentOptions(
raw: BuildEnvironmentOptions,
logger: Logger,
consumer: 'client' | 'server' | undefined,
// Backward compatibility
isSsrTargetWebworkerEnvironment?: boolean,
): ResolvedBuildEnvironmentOptions {
const deprecatedPolyfillModulePreload = raw?.polyfillModulePreload
const { polyfillModulePreload, ...rest } = raw
Expand Down Expand Up @@ -453,19 +451,6 @@ export function resolveBuildEnvironmentOptions(
},
}

if (isSsrTargetWebworkerEnvironment) {
resolved.rollupOptions ??= {}
resolved.rollupOptions.output ??= {}
const output = resolved.rollupOptions.output
for (const out of arraify(output)) {
out.entryFileNames ??= `[name].js`
out.chunkFileNames ??= `[name]-[hash].js`
const input = resolved.rollupOptions.input
out.inlineDynamicImports ??=
!input || typeof input === 'string' || Object.keys(input).length === 1
}
}

return resolved
}

Expand Down Expand Up @@ -677,6 +662,10 @@ async function buildEnvironment(
logger.error(e.message, { error: e })
}

const isSsrTargetWebworkerEnvironment =
environment.name === 'ssr' &&
environment.getTopLevelConfig().ssr?.target === 'webworker'

let bundle: RollupBuild | undefined
let startTime: number | undefined
try {
Expand Down Expand Up @@ -706,7 +695,7 @@ async function buildEnvironment(

const format = output.format || 'es'
const jsExt =
environment.config.consumer === 'server' || libOptions
(ssr && !isSsrTargetWebworkerEnvironment) || libOptions
? resolveOutputJsExtension(
format,
findNearestPackageData(root, packageCache)?.data.type,
Expand Down Expand Up @@ -744,7 +733,10 @@ async function buildEnvironment(
? `[name].[ext]`
: path.posix.join(options.assetsDir, `[name]-[hash].[ext]`),
inlineDynamicImports:
output.format === 'umd' || output.format === 'iife',
output.format === 'umd' ||
output.format === 'iife' ||
(isSsrTargetWebworkerEnvironment &&
(typeof input === 'string' || Object.keys(input).length === 1)),
...output,
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,6 @@ function resolveEnvironmentOptions(
options.build ?? {},
logger,
consumer,
isSsrTargetWebworkerEnvironment,
),
}
}
Expand Down

0 comments on commit b39e696

Please sign in to comment.