Skip to content

Latest commit

 

History

History

electron-vite

Folders and files

README.md

electron-vite + electron-asar-updater

Demonstrates integrating electron-asar-updater into a standard electron-vite project.

Project Structure

├── build/
│   └── afterpack.js        ← electron-builder afterPack hook
├── src/
│   ├── main/index.js       ← main process (your app logic)
│   ├── preload/index.js    ← preload script
│   └── renderer/
│       ├── index.html      ← renderer entry
│       └── src/main.js     ← renderer JS
├── bootstrap.js                ← bootstrap entry (generated by `init`, production only)
├── electron.vite.config.mjs
├── electron-builder.yml
└── package.json

How It Works

Development (npm run dev): electron-vite runs as usual — src/main/index.js is the entry, HMR works for the renderer. bootstrap.js is not involved.

Production build (npm run build):

  1. electron-vite build compiles src/ → out/ (main, preload, renderer)
  2. electron-builder packs everything into app.asar as normal
  3. afterpack.js hook runs:
    • Renames app.asar → core.asar (contains your full app)
    • Signs core.asar with RSA-SHA256 (signature embedded in file tail)
    • Creates a new minimal app.asar containing only bootstrap.js + electron-asar-updater

Runtime: Electron loads app.asar/bootstrap.js → bootstrap() verifies and loads core.asar.

Setup

# Install dependencies
npm install

# Generate keys + bootstrap.js (public key auto-embedded)
npx electron-asar-updater init

Development

npm run dev

Production Build

# Build for current platform
npm run build

# Or target a specific platform
npm run build:win
npm run build:mac
npm run build:linux

Quick Demo (hot-update)

After building, use the shared demo server to test the full update flow:

cd ../demo && npm install
npm run demo:vite

Then launch the built app and click "Check for Update" → "Restart Now" → see v2.0.0.

Key Differences from a Standard electron-vite Project

Only 3 additions to a normal electron-vite setup:

File Purpose
bootstrap.js Bootstrap that loads core.asar in production
build/afterpack.js Renames + signs asar during build
afterPack in electron-builder.yml Points to the hook

Everything else (electron-vite config, src/ structure, dev workflow) stays exactly the same.