Huakun

Tauri Plugin JS

A Tauri v2 plugin that spawns and manages JavaScript runtime processes (Bun, Node.js, Deno) from your desktop app

A Tauri v2 plugin that spawns and manages JavaScript runtime processes (Bun, Node.js, Deno) from your desktop app.

GitHub: https://github.com/HuakunShen/tauri-plugin-js

Why

Tauri gives you a tiny, fast, secure desktop shell — but sometimes you need a full JS runtime for things the webview can't do: filesystem watchers, native modules, long-running compute, local AI inference, dev servers, etc. This plugin bridges that gap without the weight of Electron.

Features

  • Run Bun/Node/Deno workers from a Tauri app with full process lifecycle management
  • Type-safe bidirectional RPC between frontend and backend JS processes via kkrpc
  • Multiple concurrent named processes with independent stdio streams
  • Runtime auto-detection (discovers installed runtimes, paths, versions)
  • Custom runtime executable paths via settings
  • Compiled binary sidecars — compile TS workers into standalone executables
  • Clean shutdown on app exit
  • Multi-window support

Architecture

┌─────────────────┐                 ┌─────────────────┐
│  Browser Host   │  ◄─postMessage─►│  Web Worker     │
│  (Svelte)       │                 │  (Plugin)       │
└─────────────────┘                 └─────────────────┘

Rust never parses RPC payloads — it forwards raw newline-delimited strings between the webview and child processes. The RPC protocol layer (kkrpc) runs entirely in JS on both sides.

Installation

Rust

[dependencies]
tauri-plugin-js = "0.1"

Frontend

pnpm add tauri-plugin-js-api kkrpc

Usage

import {
  spawn,
  createChannel,
  onStdout,
  onStderr,
  onExit,
} from "tauri-plugin-js-api";
import type { BackendAPI } from "../backends/shared-api";

// Spawn a worker
await spawn("my-worker", { runtime: "bun", script: "bun-worker.ts" });

// Create a typed RPC channel
const { api } = await createChannel<Record<string, never>, BackendAPI>(
  "my-worker",
);

// Type-safe calls
const sum = await api.add(5, 3);
const info = await api.getSystemInfo();

Compiled Binary Sidecars

Both Bun and Deno can compile TS workers into standalone executables:

# Bun
bun build --compile --minify backends/bun-worker.ts --outfile src-tauri/binaries/bun-worker-$TARGET

# Spawn sidecar — no runtime needed at runtime
await spawn("my-compiled-worker", { sidecar: "bun-worker" });

Use Cases

  • Dev servers embedded in desktop apps
  • File system watchers and build tools
  • Long-running background tasks
  • Native module access without node-gyp
  • Local AI inference with GPU acceleration

On this page