Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/electron-is-dev
Check if Electron is running in development
https://github.com/sindresorhus/electron-is-dev
Last synced: 6 days ago
JSON representation
Check if Electron is running in development
- Host: GitHub
- URL: https://github.com/sindresorhus/electron-is-dev
- Owner: sindresorhus
- License: mit
- Created: 2016-04-08T16:13:13.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-01-13T14:58:38.000Z (11 months ago)
- Last Synced: 2024-12-01T01:37:05.509Z (11 days ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 428
- Watchers: 10
- Forks: 34
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-github-star - electron-is-dev
- awesome-electron - electron-is-dev - Check if Electron is running in development. (Tools / For Electron)
- awesome-electron - electron-is-dev - Check if Electron is running in development. ![](https://img.shields.io/github/stars/sindresorhus/electron-is-dev.svg?style=social&label=Star) (Library / Check/Detect)
- awesome-electron-zh - electron-is-dev - Check if Electron is running in development. (Tools / For Electron)
README
# electron-is-dev
> Check if [Electron](https://electronjs.org) is running in development
Useful for enabling debug features only during development.
This package must be used from the Electron main process.
## Install
```sh
npm install electron-is-dev
```*Requires Electron 28 or later.*
## Usage
```js
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
### How is this different than [`app.isPackaged`](https://www.electronjs.org/docs/api/app#appispackaged-readonly)?
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`](https://www.electronjs.org/docs/latest/api/context-bridge) in the [preload script](https://www.electronjs.org/docs/latest/tutorial/tutorial-preload) to manually expose the variable:
```js
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:
```js
console.log(globalThis.isDev);
```## Related
- [electron-util](https://github.com/sindresorhus/electron-util) - Useful utilities for developing Electron apps
- [electron-debug](https://github.com/sindresorhus/electron-debug) - Adds useful debug features to your Electron app