#Hot module reloading

4 messages · Page 1 of 1 (latest)

sharp dirge
#

Hello everyone, I am very new to Electron (just picked it up last night). The project is using electron-builder, better-sqlite3, vite, typescript, and react.

After introducing preload scripts to my project, I am no longer able to perform hot module reloading(?) in development mode.

For development, I am running the React application in the browser. Then, I run the Electron process and make it load that.

if (isDev()) {
    // Developer mode
    win.loadURL('http://localhost:7070')
  } else {
    // Production mode
    win.loadFile(path.join(app.getAppPath(), '/dist-react/index.html'))
  }

However, this means that the frontend runs in a regular browser context, not Electron, so any invokes to my preload script is undefined — causing the dev server to crash or fail to reload properly.

So now, when I try to use window.api in my App.tsx, it doesn't work.

<p>{window.api.getMemory()}</p>

Is there any workaround? The app still functions properly in production. Here are my dev and production scripts.

"dev:electron": "npm run transpile:electron && cross-env NODE_ENV=development electron .",
"prod:electron": "npm run build && npm run transpile:electron && cross-env NODE_ENV=production electron .",
jaunty gyro
sharp dirge