2017-08-14 160 views
0

如果你想增加節點的內存限制,該選項傳遞將是:增加使用節點內存NPM的package.json腳本

node --max-old-space-size=4096 yourFile.js

但在我的情況下,我使用的紗線,我的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機器上執行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時有問題。即使我使用哪個npm,仍然無法識別which

感謝您的幫助。

回答

0

回答我自己:使用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", 

這樣它的工作原理!