Electrobun

1.16.0 · active · verified Tue Apr 21

Electrobun is a framework designed for building ultra-fast, tiny, and cross-platform desktop applications using TypeScript. Leveraging the Bun runtime for the main process and native system WebViews (WebKit on macOS, WebView2 on Windows, WebKitGTK on Linux) for rendering, it offers a compelling alternative to Electron by drastically reducing bundle sizes (often around 12-64MB) and memory footprint, as it avoids bundling a full Chromium instance. The framework provides a complete TypeScript-first API for both main and renderer processes, including type-safe RPC for inter-process communication, and eliminates the need for languages like Rust (as seen in Tauri). It boasts a differential update mechanism (bsdiff) allowing for extremely small application updates, sometimes as low as 4KB. Current stable versions are `v1.x`, with active beta development continuing in the `v1.17.x-beta` series, indicating a frequent release cadence for enhancements and fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes a new Electrobun project, demonstrates basic main process window creation, a preload script for exposing IPC to the renderer, and shows how to run the application in development mode.

bunx electrobun init my-electrobun-app
cd my-electrobun-app
bun install

// src/main.ts (main Bun process)
import { BrowserWindow, app } from 'electrobun/bun';
import { join } from 'path';

app.on('ready', () => {
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: join(app.getAppPath(), 'renderer', 'preload.ts'),
      // sandbox: true, // Enable for untrusted content
    },
    title: 'Hello Electrobun App',
    url: 'views://main/index.html' // or a remote URL like 'https://electrobun.dev'
  });

  // For development, open DevTools.
  // mainWindow.webContents.openDevTools();
});

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

// src/renderer/preload.ts (preload script for webview context)
import { ipcRenderer } from 'electrobun/view';

// Expose ipcRenderer functions to the window object for the renderer process
window.electrobun = {
  sendMessage: (channel: string, data: any) => ipcRenderer.send(channel, data),
  onMessage: (channel: string, callback: (...args: any[]) => void) => ipcRenderer.on(channel, callback),
  invoke: (channel: string, ...args: any[]) => ipcRenderer.invoke(channel, ...args)
};

// Extend Window interface globally for TypeScript to recognize window.electrobun
declare global {
  interface Window {
    electrobun: {
      sendMessage: (channel: string, data: any) => void;
      onMessage: (channel: string, callback: (...args: any[]) => void) => void;
      invoke: (channel: string, ...args: any[]) => Promise<any>;
    };
  }
}

// package.json (add scripts)
//  ...
//  "scripts": {
//    "dev": "electrobun dev",
//    "start": "bun run dev",
//    "build": "electrobun build"
//  },
//  ...

bun run dev

view raw JSON →