From 4e3fce40c9bab261f3c5e31833475c3e2c6ba0cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0?= Date: Thu, 15 May 2025 13:45:43 +0900 Subject: [PATCH] fix: skip fields not supported by rolldown for rolldown-vite (#4747) --- src/node/build/bundle.ts | 92 +++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/src/node/build/bundle.ts b/src/node/build/bundle.ts index e7b0f066..a6360fa3 100644 --- a/src/node/build/bundle.ts +++ b/src/node/build/bundle.ts @@ -1,6 +1,7 @@ import fs from 'fs-extra' import path from 'node:path' import { fileURLToPath } from 'node:url' +import * as vite from 'vite' import { build, normalizePath, @@ -98,9 +99,12 @@ export async function bundle( app: path.resolve(APP_PATH, ssr ? 'ssr.js' : 'index.js'), ...input }, - // important so that each page chunk and the index export things for each - // other - preserveEntrySignatures: 'allow-extension', + // @ts-ignore skip setting it for rolldown-vite since it doesn't support `preserveEntrySignatures` yet + ...(vite.rolldownVersion + ? undefined + : // important so that each page chunk and the index export things for each + // other + { preserveEntrySignatures: 'allow-extension' }), output: { sanitizeFileName, ...rollupOptions?.output, @@ -118,44 +122,52 @@ export async function bundle( ? `${config.assetsDir}/chunks/ui-custom.[hash].js` : `${config.assetsDir}/chunks/[name].[hash].js` }, - manualChunks(id, ctx) { - // move known framework code into a stable chunk so that - // custom theme changes do not invalidate hash for all pages - if ( - id.startsWith('\0vite') || - ctx.getModuleInfo(id)?.meta['vite:asset'] - ) { - return 'framework' - } - if (id.includes('plugin-vue:export-helper')) { - return 'framework' - } - if ( - id.includes(`${clientDir}/app`) && - id !== `${clientDir}/app/index.js` - ) { - return 'framework' - } - if ( - isEagerChunk(id, ctx.getModuleInfo) && - /@vue\/(runtime|shared|reactivity)/.test(id) - ) { - return 'framework' - } + // @ts-ignore skip setting it for rolldown-vite since it doesn't support `manualChunks` + ...(vite.rolldownVersion + ? undefined + : { + manualChunks( + id: string, + ctx: Pick + ) { + // move known framework code into a stable chunk so that + // custom theme changes do not invalidate hash for all pages + if ( + id.startsWith('\0vite') || + ctx.getModuleInfo(id)?.meta['vite:asset'] + ) { + return 'framework' + } + if (id.includes('plugin-vue:export-helper')) { + return 'framework' + } + if ( + id.includes(`${clientDir}/app`) && + id !== `${clientDir}/app/index.js` + ) { + return 'framework' + } + if ( + isEagerChunk(id, ctx.getModuleInfo) && + /@vue\/(runtime|shared|reactivity)/.test(id) + ) { + return 'framework' + } - if ( - (id.startsWith(`${clientDir}/theme-default`) || - !excludedModules.some((i) => id.includes(i))) && - staticImportedByEntry( - id, - ctx.getModuleInfo, - cacheTheme, - themeEntryRE - ) - ) { - return 'theme' - } - } + if ( + (id.startsWith(`${clientDir}/theme-default`) || + !excludedModules.some((i) => id.includes(i))) && + staticImportedByEntry( + id, + ctx.getModuleInfo, + cacheTheme, + themeEntryRE + ) + ) { + return 'theme' + } + } + }) }) } }