's'
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user