🔨 chore: fix Vercel build process (#11092)

* Update package.json

* Update next.config.ts

* improve webpack handling

* 调整构建命令以增加内存限制并更新 Vercel 构建命令
This commit is contained in:
sxjeru
2026-01-01 19:18:38 +08:00
committed by GitHub
parent 789c302e2e
commit 479556b39a
4 changed files with 35 additions and 12 deletions

View File

@@ -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;

View File

@@ -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",

View File

@@ -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;
},
};

View File

@@ -1,4 +1,4 @@
{
"buildCommand": "bun run build",
"buildCommand": "bun run build:vercel",
"installCommand": "npx bun@1.2.23 install"
}