Skip to content

Commit e168602

Browse files
authored
fix: skip manualChunks if Vite 8's codeSplitting is used (#3227) (#3230)
1 parent b14acc9 commit e168602

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

packages/vike/src/node/vite/plugins/build/pluginDistFileNames.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type { Plugin, ResolvedConfig, Rollup } from 'vite'
1414
import { getAssetsDir } from '../../shared/getAssetsDir.js'
1515
import { assertModuleId, getFilePathToShowToUserModule } from '../../shared/getFilePath.js'
1616
import '../../assertEnvVite.js'
17+
import { isVersionMatch } from '../../../../utils/assertVersion.js'
1718
type PreRenderedChunk = Rollup.PreRenderedChunk
1819
type PreRenderedAsset = Rollup.PreRenderedAsset
1920

@@ -52,7 +53,8 @@ function pluginDistFileNames(): Plugin[] {
5253
"Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.",
5354
)
5455
}
55-
{
56+
57+
if (disableCSSBundling(config)) {
5658
const manualChunksOriginal = rollupOutput.manualChunks
5759
rollupOutput.manualChunks = function (id, ...args) {
5860
if (manualChunksOriginal) {
@@ -67,8 +69,6 @@ function pluginDistFileNames(): Plugin[] {
6769
}
6870
}
6971

70-
// Disable CSS bundling to workaround https://github.com/vikejs/vike/issues/1815
71-
// TO-DO/eventually: let's bundle CSS again once Rolldown replaces Rollup
7272
if (id.endsWith('.css')) {
7373
const userRootDir = config.root
7474
if (id.startsWith(userRootDir)) {
@@ -292,3 +292,24 @@ function getRollupOutputs(config: ResolvedConfig) {
292292
}
293293
return output
294294
}
295+
296+
function disableCSSBundling(config: ResolvedConfig) {
297+
// Vite 7 => disable CSS bundling, see: https://github.com/vikejs/vike/issues/1815
298+
if (!isVite8OrAbove(config)) return true
299+
300+
// Vite 8 doesn't support `manualChunks` when `codeSplitting` is used.
301+
// - It does, however, support `manualChunks` if `codeSplitting` isn't used (despite what the following migration guide says)
302+
// - https://vite.dev/guide/migration#removed-object-form-build-rollupoptions-output-manualchunks-and-deprecate-function-form-one
303+
// @ts-ignore
304+
if (!config.build?.rolldownOptions?.output?.codeSplitting) return true
305+
306+
// TO-DO/eventually: we should probably show a warning, because Vite 8 still builds the client and server separately (potentially leading to the CSS duplication bug):
307+
// https://github.com/vitejs/ecosystem/issues/6
308+
return false
309+
}
310+
311+
function isVite8OrAbove(config: ResolvedConfig) {
312+
const viteVersion = config._viteVersionResolved
313+
assert(viteVersion)
314+
return isVersionMatch(viteVersion, ['8.0.0'])
315+
}

test-e2e.config.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ function tolerateError({ logSource, logText, testInfo }) {
8585
'`@vitejs/plugin-react-oxc` for improved performance',
8686
// [12:21:54.297][/test/photon-vercel/.test-dev.test.ts][pnpm run dev][stderr] You or a plugin you are using have set `optimizeDeps.esbuildOptions` but this option is now deprecated. Vite now uses Rolldown to optimize the dependencies. Please use `optimizeDeps.rolldownOptions` instead.
8787
'`optimizeDeps.esbuildOptions` but this option is now deprecated',
88-
// [12:23:29.908][/test/universal-deploy/test-preview.test.ts][pnpm run preview][stderr] [warn] `manualChunks` option is ignored because the `codeSplitting` option is specified.
89-
'`manualChunks` option is ignored because the `codeSplitting`',
9088
// [12:52:00.813][/examples/react-full][pnpm run dev][stderr] [vite:react-swc] We recommend switching to `@vitejs/plugin-react` for improved performance as no swc plugins are used. More information at https://vite.dev/rolldown
9189
'We recommend switching to `@vitejs/plugin-react`',
9290
// [09:37:55.007][/examples/react-full][npm run preview][stderr] 9:37:55 AM [vite] warning: `esbuild` option was specified by "vite:react-swc" plugin. This option is deprecated, please use `oxc` instead.

0 commit comments

Comments
 (0)