Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔨 chore: fix Vercel build process (#11092)

sxjeru479556b39ab7
diff --git a/next.config.ts b/next.config.ts
index 8807325cce1..0c8f58385ac 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 8435009385a..c3e277bbb39 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 199ed845011..d9b6eacf958 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 91d92d5df47..4bd109378b8 100644
--- a/vercel.json
+++ b/vercel.json
@@ -1,4 +1,4 @@
{
- "buildCommand": "bun run build",
+ "buildCommand": "bun run build:vercel",
"installCommand": "npx [email protected] install"
}