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: disable inlineDynamicImports for ssr.target = node #8641

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/guide/migration.md
Expand Up @@ -62,6 +62,8 @@ Vite v3 uses ESM for the SSR build by default. When using ESM, the [SSR external

If using ESM for SSR isn't possible in your project, you can set `legacy.buildSsrCjsExternalHeuristics` to generate a CJS bundle using the same externalization strategy of Vite v2.

Also [`build.rollupOptions.output.inlineDynamicImports`](https://rollupjs.org/guide/en/#outputinlinedynamicimports) now defaults to `false` when `ssr.target` is `'node'`. `inlineDynamicImports` changes execution order and bundling to a single file is not needed for node builds.

## General Changes

- JS file extensions in SSR and lib mode now use a valid extension (`js`, `mjs`, or `cjs`) for output JS entries and chunks based on their format and the package type.
Expand Down
5 changes: 3 additions & 2 deletions packages/vite/src/node/build.ts
Expand Up @@ -447,10 +447,11 @@ async function doBuild(
)
}

const ssrWorkerBuild = ssr && config.ssr?.target !== 'webworker'
const cjsSsrBuild = ssr && config.ssr?.format === 'cjs'
const format = output.format || (cjsSsrBuild ? 'cjs' : 'es')
const jsExt =
(ssr && config.ssr?.target !== 'webworker') || libOptions
ssrWorkerBuild || libOptions
? resolveOutputJsExtension(format, getPkgJson(config.root)?.type)
: 'js'
return {
Expand Down Expand Up @@ -478,7 +479,7 @@ async function doBuild(
inlineDynamicImports:
output.format === 'umd' ||
output.format === 'iife' ||
(ssr && typeof input === 'string'),
(ssrWorkerBuild && typeof input === 'string'),
...output
}
}
Expand Down