使用 npm package.json 脚本增加节点内存
Increase node memory using npm package.json script
如果要增加节点中的内存限制,要传递的选项将是:
node --max-old-space-size=4096 yourFile.js
但在我使用 yarn 的场景中,我的 package.json 看起来像这样:
{
"name": "myapp",
"productName": "myapp",
"version": "1.0.0",
"main": "app/main.js",
...
"scripts": {
"package-win": "npm run build && build --win --x64",
"package-mac": "npm run build && build --mac",
...
},
...
我在 windows machine 上执行 yarn package-win
来为我使用 react.js 构建的电子应用程序调用电子构建器。但是我总是 npm ERR! code ELIFECYCLE
由于内存不足。在我的 mac 中也出现了 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
错误,但在调用 yarn package-mac
.
时仍然生成了包(如何?我不知道)
我搜索了很多有关如何使用 --max-old-space-size=4096
选项的信息,但我没有找到任何有用的东西。
我试过了"package-win": "node --max-old-space-size=4096 npm run build && build --win --x64",
但是路径在定位npm时有问题。即使我使用 which npm,仍然无法识别 which
。
感谢您的帮助。
对自己的回答:在 package-win
中使用此选项是错误的。当 package-win 执行构建任务时,则:
"build": "npm run build-main && npm run build-renderer",
...
"build-main": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.main.prod.js --progress --profile --colors",
"build-renderer": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.prod.js --progress --profile --colors",
这样就可以了!
您不必在 package-win 中使用选项。
你应该使用的方式-
"build-ts-prod": "node --max-old-space-size=1024
./node_modules/typescript/bin/tsc --skipLibCheck --diagnostics",
如果要增加节点中的内存限制,要传递的选项将是:
node --max-old-space-size=4096 yourFile.js
但在我使用 yarn 的场景中,我的 package.json 看起来像这样:
{
"name": "myapp",
"productName": "myapp",
"version": "1.0.0",
"main": "app/main.js",
...
"scripts": {
"package-win": "npm run build && build --win --x64",
"package-mac": "npm run build && build --mac",
...
},
...
我在 windows machine 上执行 yarn package-win
来为我使用 react.js 构建的电子应用程序调用电子构建器。但是我总是 npm ERR! code ELIFECYCLE
由于内存不足。在我的 mac 中也出现了 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
错误,但在调用 yarn package-mac
.
我搜索了很多有关如何使用 --max-old-space-size=4096
选项的信息,但我没有找到任何有用的东西。
我试过了"package-win": "node --max-old-space-size=4096 npm run build && build --win --x64",
但是路径在定位npm时有问题。即使我使用 which npm,仍然无法识别 which
。
感谢您的帮助。
对自己的回答:在 package-win
中使用此选项是错误的。当 package-win 执行构建任务时,则:
"build": "npm run build-main && npm run build-renderer",
...
"build-main": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.main.prod.js --progress --profile --colors",
"build-renderer": "cross-env NODE_ENV=production node --max_old_space_size=6144 --optimize_for_size --stack_size=6144 --trace-warnings -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.renderer.prod.js --progress --profile --colors",
这样就可以了!
您不必在 package-win 中使用选项。 你应该使用的方式-
"build-ts-prod": "node --max-old-space-size=1024
./node_modules/typescript/bin/tsc --skipLibCheck --diagnostics",