Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Packaging a Web Application into a Desktop Client Using Electron-Packager

Tech May 10 3
  1. Clone the Electron repository
git clone https://github.com/electron/electron-quick-start
  1. Transfer the web application files into the electron-quick-start directory.

  2. Modify main.js to load the desired HTML file.

const { app, BrowserWindow, Menu } = require('electron');
const path = require('path');
const httpServer = require('http-server');

function createWindow() {
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  });

  Menu.setApplicationMenu(null);
  mainWindow.loadFile('output/index.html');
  httpServer.createServer({ root: './output' }).listen(80);
}
  1. Install the packaging tool and configure the build script.
npm install electron-packager

Update package.json with the following script:

{
  "scripts": {
    "start": "electron .",
    "packager": "electron-packager ./ APP --platform=win32 --arch=x64 --electron-version=19.0.6 --icon=logo.ico --overwrite"
  }
}

Command breakdown:

electron-packager <project location> <app name> <platform> <architecture> <electron version> <optional flags>

Example usage:

electron-packager ./ helloworld --platform=win32 --arch=x64 --out=./app --electron-version=3.0.7
  1. Execute the packaging command:
npm run packager

Common issues and solutions:

  1. Timeout during packaging
# For yarn
yarn config set electron_mirror https://npmmirror.com/mirrors/electron/

# For npm
npm config set ELECTRON_MIRROR https://npmmirror.com/mirrors/electron/
  1. Icon-related errors
rcedit.exe failed with exit code 1. Reserved header is not 0 or image type is not icon for './src/assets/olami.ico'

Solution:

Download an ICO generator tool from https://icofx.ro/. Use it to convert images to .ico format.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.