What is electron-is-dev?
The electron-is-dev package is a simple utility for Electron applications to determine if the app is running in development mode. This can be useful for conditionally enabling or disabling certain features or behaviors during development versus production.
What are electron-is-dev's main functionalities?
Check if in development mode
This feature allows you to check if the Electron app is running in development mode. The code sample demonstrates how to use the electron-is-dev package to log different messages based on the environment.
const isDev = require('electron-is-dev');
if (isDev) {
console.log('Running in development');
} else {
console.log('Running in production');
}
Other packages similar to electron-is-dev
electron-devtools-installer
The electron-devtools-installer package is used to install DevTools extensions in Electron applications. While it serves a different primary purpose, it is often used in conjunction with electron-is-dev to conditionally install DevTools extensions only in development mode.
electron-debug
The electron-debug package adds useful debug features to your Electron app, such as keyboard shortcuts for opening DevTools and reloading the window. It can be used alongside electron-is-dev to enable these features only during development.
electron-reload
The electron-reload package provides live reloading for Electron applications. It is similar to electron-is-dev in that it is typically used during development to improve the developer experience by automatically reloading the app when files change.
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 electron-is-dev
Requires Electron 28 or later.
Usage
import isDev from '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
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