From 479556b39ab7a7ace70c96e9f174e9fed3160742 Mon Sep 17 00:00:00 2001 From: sxjeru <20513115+sxjeru@users.noreply.github.com> Date: Thu, 1 Jan 2026 19:18:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20chore:=20fix=20Vercel=20build=20?= =?UTF-8?q?process=20(#11092)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update package.json * Update next.config.ts * improve webpack handling * 调整构建命令以增加内存限制并更新 Vercel 构建命令 --- next.config.ts | 15 +++++++++++++- package.json | 1 + src/libs/next/config/define-config.ts | 29 ++++++++++++++++++--------- vercel.json | 2 +- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/next.config.ts b/next.config.ts index 8807325cce..0c8f58385a 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,5 +1,18 @@ import { defineConfig } from './src/libs/next/config/define-config'; -const nextConfig = defineConfig({}); +const nextConfig = defineConfig({ + experimental: { + webpackBuildWorker: true, + webpackMemoryOptimizations: true, + }, + webpack: (webpackConfig, context) => { + const { dev } = context; + if (!dev) { + webpackConfig.cache = false; + } + + return webpackConfig; + }, +}); export default nextConfig; diff --git a/package.json b/package.json index 8435009385..c3e277bbb3 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "build:analyze": "NODE_OPTIONS=--max-old-space-size=8192 ANALYZE=true next build --webpack", "build:docker": "npm run prebuild && NODE_OPTIONS=--max-old-space-size=8192 DOCKER=true next build --webpack && npm run build-sitemap", "build:electron": "cross-env NODE_OPTIONS=--max-old-space-size=8192 NEXT_PUBLIC_IS_DESKTOP_APP=1 tsx scripts/electronWorkflow/buildNextApp.mts", + "build:vercel": "npm run prebuild && cross-env NODE_OPTIONS=--max-old-space-size=6144 next build --webpack", "clean:node_modules": "bash -lc 'set -e; echo \"Removing all node_modules...\"; rm -rf node_modules; pnpm -r exec rm -rf node_modules; rm -rf apps/desktop/node_modules; echo \"All node_modules removed.\"'", "db:generate": "drizzle-kit generate && npm run db:generate-client && npm run workflow:dbml", "db:generate-client": "tsx ./scripts/migrateClientDB/compile-migrations.ts", diff --git a/src/libs/next/config/define-config.ts b/src/libs/next/config/define-config.ts index 199ed84501..d9b6eacf95 100644 --- a/src/libs/next/config/define-config.ts +++ b/src/libs/next/config/define-config.ts @@ -6,9 +6,11 @@ import type { Header, Redirect } from 'next/dist/lib/load-custom-routes'; import ReactComponentName from 'react-scan/react-component-name/webpack'; interface CustomNextConfig { + experimental?: NextConfig['experimental']; headers?: Header[]; redirects?: Redirect[]; turbopack?: NextConfig['turbopack']; + webpack?: NextConfig['webpack']; } export function defineConfig(config: CustomNextConfig) { @@ -56,6 +58,7 @@ export function defineConfig(config: CustomNextConfig) { webVitalsAttribution: ['CLS', 'LCP'], webpackBuildWorker: true, webpackMemoryOptimizations: true, + ...config.experimental, }, async headers() { const securityHeaders = [ @@ -325,20 +328,20 @@ export function defineConfig(config: CustomNextConfig) { ignoreBuildErrors: true, }, - webpack(config) { - config.experiments = { + webpack(baseWebpackConfig, options) { + baseWebpackConfig.experiments = { asyncWebAssembly: true, layers: true, }; // 开启该插件会导致 pglite 的 fs bundler 被改表 if (enableReactScan) { - config.plugins.push(ReactComponentName({})); + baseWebpackConfig.plugins.push(ReactComponentName({})); } // to fix shikiji compile error // refs: https://github.com/antfu/shikiji/issues/23 - config.module.rules.push({ + baseWebpackConfig.module.rules.push({ resolve: { fullySpecified: false, }, @@ -347,14 +350,14 @@ export function defineConfig(config: CustomNextConfig) { }); // https://github.com/pinojs/pino/issues/688#issuecomment-637763276 - config.externals.push('pino-pretty'); + baseWebpackConfig.externals.push('pino-pretty'); - config.resolve.alias.canvas = false; + baseWebpackConfig.resolve.alias.canvas = false; // to ignore epub2 compile error // refs: https://github.com/lobehub/lobe-chat/discussions/6769 - config.resolve.fallback = { - ...config.resolve.fallback, + baseWebpackConfig.resolve.fallback = { + ...baseWebpackConfig.resolve.fallback, zipfile: false, }; @@ -364,7 +367,7 @@ export function defineConfig(config: CustomNextConfig) { ) { // fix the Worker URL cross-origin issue // refs: https://github.com/lobehub/lobe-chat/pull/9624 - config.module.rules.push({ + baseWebpackConfig.module.rules.push({ generator: { // @see https://webpack.js.org/configuration/module/#rulegeneratorpublicpath publicPath: '/_next/', @@ -375,7 +378,13 @@ export function defineConfig(config: CustomNextConfig) { }); } - return config; + const updatedConfig = baseWebpackConfig; + + if (config.webpack) { + return config.webpack(updatedConfig, options); + } + + return updatedConfig; }, }; diff --git a/vercel.json b/vercel.json index 91d92d5df4..4bd109378b 100644 --- a/vercel.json +++ b/vercel.json @@ -1,4 +1,4 @@ { - "buildCommand": "bun run build", + "buildCommand": "bun run build:vercel", "installCommand": "npx bun@1.2.23 install" }