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(ssr): set ssr.target: 'webworker' defaults as fallback #18827

Merged
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
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ssr is environment.config.consumer === 'server'.

const ssr = environment.config.consumer === 'server'

? 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