All Projects β†’ manidlou β†’ elemon

manidlou / elemon

Licence: MIT license
live-reload Electron application during development

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to elemon

live-reload-vanilla-website-template
Template to build a website without a front-end framework, including transpilation of ES6+ JavaScript and Sass support
Stars: ✭ 47 (-33.8%)
Mutual labels:  live-reload
docker-rabbitmq-node
🐳 A playground for Docker with RabbitMQ and Node.
Stars: ✭ 32 (-54.93%)
Mutual labels:  live-reload
rebirth
Supports live reloading for Go
Stars: ✭ 60 (-15.49%)
Mutual labels:  live-reload
learn-ngrok
☁️ Learn how to use ngrok to share access to a Web App/Site running on your "localhost" with the world!
Stars: ✭ 50 (-29.58%)
Mutual labels:  live-reload
vscode-live-server-plus-plus
VsCode Live Server++ : It's Truly Live 😊 (BETA) -- [NOT RELEASED YET]
Stars: ✭ 198 (+178.87%)
Mutual labels:  live-reload
tower
εŸΊδΊŽεε‘δ»£η†ηš„Golang即既编译ε·₯ε…·οΌŒε―εœ¨η”ŸδΊ§ηŽ―ε’ƒδΈ‹ζ— ηΌεˆ‡ζ’εˆ°ζ–°η‰ˆζœ¬
Stars: ✭ 21 (-70.42%)
Mutual labels:  live-reload
universal-hot-reload
Hot reload client and server webpack bundles for the ultimate development experience
Stars: ✭ 79 (+11.27%)
Mutual labels:  live-reload
Algernon
🎩 Small self-contained pure-Go web server with Lua, Markdown, HTTP/2, QUIC, Redis and PostgreSQL support
Stars: ✭ 1,880 (+2547.89%)
Mutual labels:  live-reload
arelo
a simple auto reload (live reload) utility
Stars: ✭ 54 (-23.94%)
Mutual labels:  live-reload
hotbuild
a cross platform hot compilation tool for golang
Stars: ✭ 181 (+154.93%)
Mutual labels:  live-reload
Toolbelt.Blazor.DevServer.WithCssLiveReloader
Development server for use when building Blazor applications, with CSS Live Reloader.
Stars: ✭ 18 (-74.65%)
Mutual labels:  live-reload
mock-json-server
A mock web server using a JSON file with live-reload support.
Stars: ✭ 31 (-56.34%)
Mutual labels:  live-reload
TypeScriptXX
🧷 Stay safe! Type-safe scripting for C++ using TypeScriptToLua and CMake with auto-generated declarations.
Stars: ✭ 33 (-53.52%)
Mutual labels:  live-reload
LiveReloadServer
A self-contained, local, cross-platform, static file Web Server with automatic Live Reloading, Markdown rendering and loose Razor Pages support.
Stars: ✭ 69 (-2.82%)
Mutual labels:  live-reload
Vscode Live Server
Launch a development local Server with live reload feature for static & dynamic pages.
Stars: ✭ 3,275 (+4512.68%)
Mutual labels:  live-reload
node-docker
Guide for Writing Dockerfiles for Node.js Applications
Stars: ✭ 91 (+28.17%)
Mutual labels:  live-reload
docker-nginx-certbot
Automatically create and renew website certificates for free using the Let's Encrypt certificate authority.
Stars: ✭ 367 (+416.9%)
Mutual labels:  live-reload
denoliver
A simple, dependency free static file server for Deno with possibly the worst name ever.
Stars: ✭ 94 (+32.39%)
Mutual labels:  live-reload
Air
☁️ Live reload for Go apps
Stars: ✭ 5,257 (+7304.23%)
Mutual labels:  live-reload
p5-server
Command-line tool to create and run p5.js sketches. It runs a server with live reload, sketch-aware directory listings, automatic libraries for JavaScript-only sketches.
Stars: ✭ 33 (-53.52%)
Mutual labels:  live-reload

elemon

npm

Standard JavaScript

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 [].

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].