Scripts2026年4月11日·1 分钟阅读

Tauri — Smaller, Faster, More Secure Desktop Apps in Rust

Tauri lets you build smaller, faster, and more secure desktop and mobile applications with any web frontend. Rust backend + OS native WebView (no bundled Chromium) produces ~3MB binaries compared to Electron 150MB.

SC
Script Depot · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

Prereqs: Rust toolchain (via rustup), Node.js.

# Create project
npm create tauri-app@latest
# Pick frontend: Vanilla/React/Vue/Svelte/Solid
cd my-app
npm install
npm run tauri dev

Call Rust from frontend:

// src-tauri/src/main.rs
#[tauri::command]
fn greet(name: &str) -> String {
  format!("Hello, {}!", name)
}

fn main() {
  tauri::Builder::default()
    .invoke_handler(tauri::generate_handler![greet])
    .run(tauri::generate_context!())
    .expect("error while running tauri app");
}
import { invoke } from "@tauri-apps/api/core";
const msg = await invoke<string>("greet", { name: "William" });
介绍

Tauri is a toolkit for building smaller, faster, and more secure desktop and mobile applications with a web frontend. Instead of bundling Chromium (like Electron), Tauri uses the the OS native WebView (WebKit on macOS/Linux, WebView2 on Windows) and a Rust backend.

What Tauri Does

  • Rust backend — filesystem, shell, network, native APIs
  • Commands — TypeScript → Rust function calls
  • System tray — cross-platform tray icons
  • Menus — native menu bar, context menus
  • Updater — cryptographically signed auto-updates
  • Sidecar binaries — ship extra executables
  • Mobile (v2) — iOS and Android targets
  • Permissions — granular allowlist per capability

Architecture

One process split into Core (Rust) + WebView (HTML/JS). Frontend calls Rust commands via IPC. Tauri v2 introduces a plugin system, mobile support, and fine-grained capability-based permissions (replacing the v1 allowlist).

Self-Hosting

npm run tauri build
# Produces platform-specific installers in src-tauri/target/release/bundle/
# .msi / .dmg / .app / .deb / .rpm / .AppImage

Key Features

  • 3-10MB binaries (vs Electron 150MB)
  • Rust backend (memory-safe, fast)
  • Mobile support (iOS/Android)
  • Capability-based security
  • Code signing (Windows + macOS)
  • Cross-platform installers
  • Plugin ecosystem
  • ~80MB idle memory

Comparison

Framework Size Language Mobile Runtime
Tauri 3-10MB Rust + JS Yes (v2) OS WebView
Electron ~150MB JS No Chromium + Node
Wails ~8MB Go + JS No OS WebView
Neutralino ~2MB C++ + JS No OS WebView

常见问题 FAQ

Q: WebView 不一致怎么办? A: macOS Safari vs Windows Edge vs Linux WebKitGTK 渲染差异。测试要覆盖所有目标。Tauri 2 正在改进一致性。

Q: 必须学 Rust 吗? A: 基础命令不需要。只有定制原生功能时才写 Rust。大部分 web 开发者几天能上手。

Q: v1 和 v2 区别? A: v2 有移动端支持、新 permission 系统、plugin 架构。v1 只支持桌面。

来源与致谢 Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产