运行构build时,如何为node.js分配更多的内存? (苹果电脑)

由于我的angular-cli应用程序的内存需求不断增加,我在ng build --prod期间开始遇到节点崩溃。 我见过这样的解决scheme:

 node --max_old_space_size=4096 myAwesomeServer.js 

但是如何将它应用于ng命令(尤其是ng bundle )呢?

您允许通过环境variables设置节点命令行选项:

 NODE_OPTIONS=--max-old-space-size=4096 ng bundle 

https://nodejs.org/api/cli.html#cli_node_options_options

你也可以像运行一样

 node --max-old-space-size=2048 $(which ng) bundle # not tested by myself