It's easy to make a hot reload for webpage in electron BrowserWindow, But what about the main process? every time I change some event handler code in the main process, I need to restart electron to make the code take effect, any method to solve this problem without restarting the electron process?
electron main process hot reload or live reload
There is not. Electron's main process is node.js, which doesn't support reload modules from its cache out of the box. Unless node.js have support for it, Electron will inherit same behavior.
OK, tnx, although the answer is not what I want. –
Untie
Install the nodemon package and add this to your package.json
"scripts": {
"start": "electron .",
"watch": "nodemon --exec electron ."
}
Run your code in watch mode with npm run watch or yarn watch
This certainly does the trick. It's a little quirky since the Electron window will be killed and reloaded. Fine for small projects. Alternatives may be desired for larger projects -- I am not enough of an expert to suggest details about alternatives. –
Flyer
Nodejs 21.4.0 has watch and watch path in experimental state. While this might not help directly, you can pass node options to electron
© 2022 - 2024 — McMap. All rights reserved.