electron main process hot reload or live reload
Asked Answered
U

3

6

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?

Untie answered 23/1, 2019 at 9:6 Comment(0)
P
7

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.

Private answered 23/1, 2019 at 17:29 Comment(1)
OK, tnx, although the answer is not what I want.Untie
C
3

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

Civilly answered 27/11, 2021 at 17:30 Comment(1)
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
K
0

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

https://nodejs.org/api/cli.html#--watch

Kuehnel answered 14/12, 2023 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.