webpack: Increase Node.js heap size on low-memory systems.

On a 2 GiB, 1 CPU system, webpack would hit the Node.js heap
limit (which is half of physical memory up to 4 GiB, on 64-bit
systems).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-09-21 19:28:11 -07:00 committed by Tim Abbott
parent bd3c099978
commit c3e7a22afc
1 changed files with 5 additions and 1 deletions

View File

@ -11,7 +11,11 @@ os.chdir(os.path.join(os.path.dirname(__file__), ".."))
def build_for_prod_or_puppeteer(quiet: bool) -> NoReturn:
"""Builds for production, writing the output to disk"""
webpack_args = ["node", "node_modules/.bin/webpack-cli", "--mode=production"]
webpack_args = ["node"]
with open("/proc/meminfo") as meminfo:
if int(next(meminfo).split()[1]) < 3 * 1024 * 1024:
webpack_args += ["--max-old-space-size=1536"]
webpack_args += ["node_modules/.bin/webpack-cli", "--mode=production"]
if quiet:
webpack_args += ["--stats=errors-only"]
os.execvp(webpack_args[0], webpack_args)