Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run electron in dev mode

I need to run an electron application in developer mode when I'm running locally and in production mode when the application is built, and I need to read this environment variable during the application.

I am using electron-builder in version 22.8.0 to build the application, and electron is in version 10.0.0.

Thanks :)

like image 714
Luidi Avatar asked Feb 20 '26 15:02

Luidi


2 Answers

If I understand your question, here is what I use to run electron-reload when in development. I think there are other, maybe better ways to do this now, but it has worked really well for me for a few years.

Define a var in the start script:

  "scripts": {
    "start": "APP_DEV=true electron .",
  },

Then read it in main.js:

var isDev = process.env.APP_DEV ? (process.env.APP_DEV.trim() == 'true') : false;

if (isDev) {
    require('electron-reload')(__dirname);
}
like image 53
spring Avatar answered Feb 23 '26 11:02

spring


From the Electron documentation:

app.isPackaged

A boolean property that returns true if the app is packaged, false otherwise. For many apps, this property can be used to distinguish development and production environments.

like image 25
Bas Heerschop Avatar answered Feb 23 '26 11:02

Bas Heerschop



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!