
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
elemon
is a tiny module that tries to provide a simple and yet efficient live-reload tool when developing Electron applications. You just need to pass the app
and BrowserWindows
and the name of the files that are associated with them as a parameter to the elemon
function after your app is ready
. Please check out the example below to see how you can easily use it to watch your app and cleanly reload it upon any changes. If the changed
file is the main app file, then it relaunch
the app and exit
the current instance. If the changed file is a file that is associated with a browser window, then that window will only be reloaded.
In fact, setting up a clean live-reload tool when developing an electron application is super simple by using the Electron API. The api already comes with whatever you need; just add a watcher (like chokidar or whatever watcher you like) and you are all set.
npm i elemon --save-dev
.
elemon(refs)
refs
{Object}
object that takes references to app and browser windows objects and resources
app
{Object}
main app objectmainFile
{String}
main file namebws
{Array<Object>}
array of browser window objects and their resources [{bw:, res: []}]
bw
{Object}
BrowserWindow objectres
{Array<String>}
array of any file name that is somehow associated with this browser window
bw
to be reloaded on any changes and not necessarily changes on specific file(s), leave the res
as empty []
. (thanks jaime-ez for adding this option)Suppose it is the app file structure:
example_proj
|
|__views
| |__win1.html
| |__win2.html
| |__win1.js
| |__win2.js
|
|__stylesheets
| |__style.css
|
|__main.js
then, in the main process file where usually app and browser windows are created:
main.js
const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')
const elemon = require('elemon')
let win1, win2
function createWindows () {
win1 = new BrowserWindow({width: 800, height: 600})
win1.loadURL(url.format({
pathname: path.join(__dirname, 'views', 'win1.html'),
protocol: 'file:',
slashes: true
}))
win1.on('closed', () => {
win1 = null
})
win2 = new BrowserWindow({width: 800, height: 600})
win2.loadURL(url.format({
pathname: path.join(__dirname, 'views', 'win2.html'),
protocol: 'file:',
slashes: true
}))
win2.on('closed', () => {
win2 = null
})
}
// ... and other usual stuff ... //
app.on('ready', () => {
createWindows()
// this is all that you have to add to your main app script.
// run your app normally with electron, then it will be reloaded
// based on how you define references here
elemon({
app: app,
mainFile: 'main.js',
bws: [
{bw: win1, res: ['win1.html', 'win1.js', 'style.css']},
{bw: win2, res: ['win2.html', 'win2.js', 'style.css']}
]
})
})
If you want to make sure that you don't get undefined error when you build your app, you can use elemon
along with electron-is-dev like this:
npm i electron-is-dev --save
const {app, BrowserWindow} = require('electron')
const isDev = require('electron-is-dev')
function createWindows () {
// ...
}
app.on('ready', () => {
createWindows()
if (isDev) {
const elemon = require('elemon') // require elemon if electron is in dev
elemon({
app: app,
mainFile: 'main.js',
bws: [
{bw: win1, res: ['win1.html', 'win1.js', 'style.css']},
{bw: win2, res: ['win2.html', 'win2.js', 'style.css']}
]
})
}
})
That's it. Have fun writing your Electron applications.
FAQs
live-reload electron application during development
The npm package elemon receives a total of 13 weekly downloads. As such, elemon popularity was classified as not popular.
We found that elemon demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.