This commit is contained in:
eric
2026-03-23 21:52:01 -05:00
parent c6cfb79481
commit 939db40d5c
416 changed files with 26144 additions and 2 deletions

View File

@@ -10,7 +10,21 @@ if (!process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY) {
}
}
/** 低配服务器构建:限制并行与 Turbopack 目标内存,避免 pnpm build 把机器拖死 / OOM */
const buildCpuCount = Math.max(
1,
Number.parseInt(process.env.NEXT_BUILD_CPUS ?? "1", 10) || 1,
);
const turbopackMemoryMb = Math.max(
256,
Number.parseInt(process.env.NEXT_BUILD_TURBOPACK_MEMORY_MB ?? "1536", 10) ||
1536,
);
const nextConfig: NextConfig = {
// 预渲染阶段关闭 source map降低静态生成时内存峰值需要时可设 NEXT_BUILD_PRERENDER_SOURCE_MAPS=1
enablePrerenderSourceMaps:
process.env.NEXT_BUILD_PRERENDER_SOURCE_MAPS === "1",
// 局域网访问(如手机 192.168.x.x时允许跨域请求 _next 资源
// 需完全重启 dev 服务Ctrl+C 后 pnpm dev后生效
allowedDevOrigins: [
@@ -20,6 +34,16 @@ const nextConfig: NextConfig = {
"http://192.168.41.222:3000",
"http://192.168.41.222:3001",
],
experimental: {
cpus: buildCpuCount,
memoryBasedWorkersCount: true,
turbopackMemoryLimit: turbopackMemoryMb * 1024 * 1024,
// 生产 bundle 默认不生成 Turbopack source map省内存需要 Sentry 等可设 NEXT_BUILD_TURBOPACK_SOURCE_MAPS=1
turbopackSourceMaps:
process.env.NEXT_BUILD_TURBOPACK_SOURCE_MAPS === "1",
// 静态页面导出时一次只跑少量页面,降低峰值内存
staticGenerationMaxConcurrency: 1,
},
};
export default nextConfig;