Scenario
I have a 500MB RAM build machine and I want to use it to build a JavaScript bundle using webpack.
NODE_ENV=production webpack --config webpack.prod.js
This worked fine before, but as the project grew bigger, I started running out of memory. I tried setting an upper limit for node, hoping that webpack will do something smart but nope.
NODE_OPTIONS="--max-old-space-size=2048" NODE_ENV=production webpack --config webpack.prod.js
Constraints
- Time it takes to build is not important to me. If we have to use the SSD for the build, that is fine.
- This is a Linux box, but I have no swap.
- I am happy for alternative solutions in my architecture, currently I output one single 1.6MB JS blob for my SPA.
Errors
Errors when running out of memory
FATAL ERROR: NewSpace::Rebalance Allocation failed - process out of memory
Error when I add restriction for node
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
Any help or recommendations are greatly appreciated. Thanks!
Edit: additional info
"webpack": "4.6.0",
"webpack-cli": "2.0.15",