This commit is contained in:
eric
2026-03-23 22:59:42 -05:00
parent 614f001986
commit 0528b1853a
8 changed files with 54 additions and 13 deletions

30
scripts/build-safe.cjs Normal file
View File

@@ -0,0 +1,30 @@
/**
* 低端 VPS / 小内存环境:限制 Node 堆、开启 Next 低内存构建选项。
* 用法pnpm build默认经本脚本
* 可选环境变量:
* NEXT_BUILD_HEAP_MB — Node --max-old-space-size默认 1536
*/
const { spawnSync } = require("child_process");
const path = require("path");
const heapMb = process.env.NEXT_BUILD_HEAP_MB || "1536";
const nextBin = path.join(
path.dirname(require.resolve("next/package.json")),
"dist",
"bin",
"next"
);
const result = spawnSync(
process.execPath,
["--max-old-space-size=" + heapMb, nextBin, "build"],
{
stdio: "inherit",
env: {
...process.env,
NEXT_BUILD_LOW_MEM: "1",
},
}
);
process.exit(result.status ?? 1);