3.1.4 • Published 2 years ago
@kingdanx/electron-is-dev v3.1.4
electron-is-dev
Check if Electron is running in development
Useful for enabling debug features only during development.
This package must be used from the Electron main process.
Install
npm install @kingdanx/electron-is-devRequires Electron 28 or later.
Usage
import isDev from '@kingdanx/electron-is-dev';
if (isDev) {
console.log('Running in development');
} else {
console.log('Running in production');
}I forked to add commonJS module support here
const isDev = require('@kingdax/electron-is-dev');
if (isDev) {
console.log('Running in development');
} else {
console.log('Running in production');
}You can force development mode by setting the ELECTRON_IS_DEV environment variable to 1.
FAQ
How is this different than app.isPackaged?
This package existed long before that property. The benefit of this package is that you can override the value using an environment variable.
How do I use this in the renderer process?
You can use contextBridge in the preload script to manually expose the variable:
import {contextBridge} from 'electron';
import isDev from 'electron-is-dev';
contextBridge.exposeInMainWorld('isDev', isDev);You can then access it in globalThis from the renderer process:
console.log(globalThis.isDev);Related
- electron-is-dev - The original package this one was forked from
- electron-util - Useful utilities for developing Electron apps
- electron-debug - Adds useful debug features to your Electron app