问题
- Version: "electron": "1.6.2", "electron-builder": "^16.8.2",
- Target: windows x64
I know I can add --js-flags="--max-old-space-size=4096"
when run it using electron. But Where should I put this param to the build config of electron-builder?
回答1:
In main.js, add:
app.commandLine.appendSwitch('js-flags', '--max-old-space-size=4096');
According to Supported Chrome Command Line Switches, this should be called before the ready
event is emitted. For example:
import { app } from "electron";
app.commandLine.appendSwitch('js-flags', '--max-old-space-size=4096');
app.on('ready', () => {
// ...
});
回答2:
Just wanted to add that, in my case, the max-old-space-size
flag was only being successfully applied when I placed it in my webview's "preload" script, like so (Start_WebviewPreload.ts):
import {remote} from "electron";
remote.app.commandLine.appendSwitch("js-flags", "--max-old-space-size=8192");
Placing it in the "main.js" file (the entry point of the whole program), did not do anything. (I even checked the command-line arguments using Process Hacker 2 and it didn't show any of the electron processes as having that flag until I moved the code as mentioned above)
Also, I notice that there may be some kind of race condition between the setting of the command-line flag and the execution of app.on("ready")
-- some of the time, the code above works for the main renderer process (the one not-in-the-webview), whereas other times it doesn't.
So basically: If you want to ensure your command-line switches work, apply them within the preload script for the given browser-window/web-view.
来源:https://stackoverflow.com/questions/43933951/how-to-increase-the-max-memory-limit-for-the-app-built-by-electron-builder