-
Notifications
You must be signed in to change notification settings - Fork 293
fix(vite-8): remove deprecated Rollup config options for Vite 8/Rolldown #548
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
3fb524c
109ac93
6beaa47
1e6744e
029d279
6b9d5ef
45cd355
719778e
bec552d
89c24ea
f0e3905
701a42d
10bd03c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,7 +241,7 @@ function extractStaticValue(node: any): unknown { | |
| * by a project that has Vite 8 — so we resolve from cwd, not from | ||
| * the plugin's own location. | ||
| */ | ||
| function getViteMajorVersion(): number { | ||
| export function getViteMajorVersion(): number { | ||
| try { | ||
| const require = createRequire(path.join(process.cwd(), "package.json")); | ||
| const vitePkg = require("vite/package.json"); | ||
|
|
@@ -525,6 +525,41 @@ const clientTreeshakeConfig = { | |
| moduleSideEffects: "no-external" as const, | ||
| }; | ||
|
|
||
| /** | ||
| * Get Rollup-compatible output config for client builds. | ||
| * Returns config without Vite 8/Rolldown-incompatible options. | ||
| */ | ||
| function getClientOutputConfig( | ||
| viteVersion: number, | ||
| ): typeof clientOutputConfig | { manualChunks: typeof clientManualChunks } { | ||
| if (viteVersion >= 8) { | ||
| // Vite 8+ uses Rolldown which doesn't support experimentalMinChunkSize | ||
| return { | ||
| manualChunks: clientManualChunks, | ||
| }; | ||
| } | ||
| // Vite 7 uses Rollup with experimentalMinChunkSize support | ||
| return clientOutputConfig; | ||
| } | ||
|
|
||
| /** | ||
| * Get Rollup-compatible treeshake config for client builds. | ||
| * Returns config without Vite 8/Rolldown-incompatible options. | ||
| */ | ||
| function getClientTreeshakeConfig( | ||
| viteVersion: number, | ||
| ): typeof clientTreeshakeConfig | { moduleSideEffects: "no-external" } { | ||
| if (viteVersion >= 8) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same feedback as Please verify that |
||
| // Vite 8+ uses Rolldown which doesn't support `preset` option | ||
| // moduleSideEffects is still supported in Rolldown | ||
| return { | ||
| moduleSideEffects: "no-external" as const, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the critical question for the whole PR: does Vite 8 / Rolldown actually respect The issue (#540) and the Vite 8 migration docs both indicate that Rolldown treeshake config should go under Could you verify this with an actual Vite 8 build? If
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment says "moduleSideEffects is still supported in Rolldown" — has this been verified? The previous bot reviews raised the same concern. If Rolldown ignores The remaining question is whether Rolldown actually supports the |
||
| }; | ||
| } | ||
| // Vite 7 uses Rollup with preset support | ||
| return clientTreeshakeConfig; | ||
| } | ||
|
|
||
| type BuildManifestChunk = { | ||
| file: string; | ||
| isEntry?: boolean; | ||
|
|
@@ -1232,15 +1267,17 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] { | |
| // avoid leaking into RSC/SSR environments where | ||
| // moduleSideEffects: 'no-external' could drop server packages | ||
| // that rely on module-level side effects. | ||
| ...(!isSSR && !isMultiEnv ? { treeshake: clientTreeshakeConfig } : {}), | ||
| ...(!isSSR && !isMultiEnv | ||
| ? { treeshake: getClientTreeshakeConfig(viteMajorVersion) } | ||
| : {}), | ||
| // Code-split client bundles: separate framework (React/ReactDOM), | ||
| // vinext runtime (shims), and vendor packages into their own | ||
| // chunks so pages only load the JS they need. | ||
| // Only apply globally for standalone client builds (CLI Pages | ||
| // Router). For multi-environment builds (App Router, Cloudflare), | ||
| // manualChunks is set per-environment on the client env below | ||
| // to avoid leaking into RSC/SSR environments. | ||
| ...(!isSSR && !isMultiEnv ? { output: clientOutputConfig } : {}), | ||
| ...(!isSSR && !isMultiEnv ? { output: getClientOutputConfig(viteMajorVersion) } : {}), | ||
| }, | ||
| }, | ||
| // Let OPTIONS requests pass through Vite's CORS middleware to our | ||
|
|
@@ -1444,8 +1481,8 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] { | |
| ...(hasCloudflarePlugin ? { manifest: true } : {}), | ||
| rollupOptions: { | ||
| input: { index: VIRTUAL_APP_BROWSER_ENTRY }, | ||
| output: clientOutputConfig, | ||
| treeshake: clientTreeshakeConfig, | ||
| output: getClientOutputConfig(viteMajorVersion), | ||
| treeshake: getClientTreeshakeConfig(viteMajorVersion), | ||
| }, | ||
| }, | ||
| }, | ||
|
|
@@ -1463,8 +1500,8 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] { | |
| ssrManifest: true, | ||
| rollupOptions: { | ||
| input: { index: VIRTUAL_CLIENT_ENTRY }, | ||
| output: clientOutputConfig, | ||
| treeshake: clientTreeshakeConfig, | ||
| output: getClientOutputConfig(viteMajorVersion), | ||
| treeshake: getClientTreeshakeConfig(viteMajorVersion), | ||
| }, | ||
| }, | ||
| }, | ||
|
|
@@ -3752,7 +3789,14 @@ export type { | |
| export type { NextConfig } from "./config/next-config.js"; | ||
|
|
||
| // Exported for CLI and testing | ||
| export { clientManualChunks, clientOutputConfig, clientTreeshakeConfig, computeLazyChunks }; | ||
| export { | ||
| clientManualChunks, | ||
| clientOutputConfig, | ||
| clientTreeshakeConfig, | ||
| computeLazyChunks, | ||
| getClientOutputConfig, | ||
| getClientTreeshakeConfig, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good that both the old constants and the new getters are exported — preserves backwards compatibility for any external consumers importing /** @deprecated Use `getClientOutputConfig()` instead — applies version-gated config. */
const clientOutputConfig = { ... }; |
||
| }; | ||
| export { augmentSsrManifestFromBundle as _augmentSsrManifestFromBundle }; | ||
| export { resolvePostcssStringPlugins as _resolvePostcssStringPlugins }; | ||
| export { _postcssCache }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: the union return type is a bit unwieldy. Since this is an exported API, a simpler signature would be easier for consumers to work with:
Same applies to
getClientTreeshakeConfigbelow. Not a blocker — the current types are correct, just verbose.