npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

elemon

v5.0.3

Published

live-reload electron application during development

Downloads

43

Readme

elemon

npm

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.

Install

npm i elemon --save-dev.

Usage

elemon(refs)

refs {Object} object that takes references to app and browser windows objects and resources

  • app {Object} main app object
  • mainFile {String} main file name
  • bws {Array<Object>} array of browser window objects and their resources [{bw:, res: []}]
    • bw {Object} BrowserWindow object
    • res {Array<String>} array of any file name that is somehow associated with this browser window
      • if you want to watch all files in dir, or if you want the 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)

Example

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.