Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Shipping a Node.js server as a native desktop app with Tauri and Bun

说明与用途

使用 Tauri 和 Bun 为 Node 服务器构建跨平台桌面应用:将服务器编译为单个可执行文件,作为 sidecar 包装,配置静态资源和下载处理,并确保进程正确清理。

问题

Users of a small Node.js LAN file‑transfer tool (MeghXL) needed a double‑clickable desktop app for macOS, Windows and Linux that hides the Node runtime.

结果

The resulting installers are 28–41 MB, launch a Tauri UI and a Bun‑compiled server, and run without requiring Node. The app handles static files, downloads, drag‑drop, and cleans up orphaned server processes.

工作流

  • 1. Choose Tauri for small bundle size and OS webview.
  • 2. Configure Tauri’s externalBin to include the compiled server binary.
  • 3. Compile the Node server to a single executable with bun build --compile (cross‑compile per target).
  • 4. Ensure all dependencies are pure JavaScript (no .node binaries).
  • 5. Name the binary <name>-<triple> matching the Rust host triple.
  • 6. Ship static assets as Tauri resources and expose their path via an environment variable (PUBLIC_DIR).
  • 7. Handle Tauri quirks: disable native drag‑drop, implement custom download handler, and tie sidecar lifecycle to parent via stdin EOF.
  • 8. Build installers for macOS, Windows and Linux separately (Tauri cannot cross‑compile).

证据

Tauri resolves sidecars by target triple. The binary must be named <name>-<triple>

来源

Bun won: bun build ./server.js --compile --target=bun-darwin-x64 --outfile meghxl-server-x86_64-apple-darwin

来源

  • 记录日期: 2026-09-15T17:00:10.192Z