's'
This commit is contained in:
30
scripts/build-safe.cjs
Normal file
30
scripts/build-safe.cjs
Normal 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);
|
||||
Reference in New Issue
Block a user