tauri
2
总安装量
2
周安装量
#67567
全站排名
安装命令
npx skills add https://github.com/wcygan/dotfiles --skill tauri
Agent 安装分布
opencode
2
antigravity
2
claude-code
2
github-copilot
2
codex
2
kimi-cli
2
Skill 文档
Tauri v2 + SvelteKit
Tauri is a framework for building tiny, fast desktop and mobile apps. It combines a Rust backend (Core Process) with a frontend rendered in the OS’s native webview â no bundled browser engine. Apps start under 600KB. We always use SvelteKit with adapter-static (SPA mode, ssr = false).
Architecture Overview
SvelteKit Frontend (WebView)
â invoke() / events / channels
â¼
âââââââââââââââââââââââââââ
â Tauri Core Process â Rust â owns OS access, state, IPC routing
â (tauri::Builder) â
âââââââââââââââââââââââââââ
â
âââ WRY: cross-platform webview rendering
âââ TAO: window creation & management
- Core Process (Rust): entry point, OS access, state, IPC hub, security enforcement
- WebView Process: renders SvelteKit app using system webview (WKWebView/Edge WebView2/webkitgtk)
- IPC: message-passing via commands (
invoke) and events â all routed through Core
Project Structure
âââ package.json
âââ svelte.config.js # adapter-static, fallback: 'index.html'
âââ src/
â âââ routes/
â â âââ +layout.ts # export const ssr = false
â âââ ...
âââ src-tauri/
âââ Cargo.toml
âââ tauri.conf.json # devUrl, frontendDist, app config
âââ build.rs # must call tauri_build::build()
âââ src/
â âââ lib.rs # Builder, commands, state
â âââ main.rs # desktop entry point
âââ capabilities/
â âââ default.json # permission bindings per window
âââ permissions/ # custom TOML permission definitions
âââ icons/
Quick Command Reference
| Rust API | Purpose |
|---|---|
#[tauri::command] |
Define a command callable from frontend |
tauri::generate_handler![cmd1, cmd2] |
Register commands with Builder |
tauri::Builder::default().manage(state) |
Register managed state |
State<'_, T> |
Access managed state in commands |
AppHandle |
Access app handle in commands |
WebviewWindow |
Access calling window in commands |
tauri::ipc::Channel<T> |
Stream data to frontend |
tauri::ipc::Response |
Return raw bytes efficiently |
app.emit("event", payload) |
Emit global event to frontend |
app.emit_to("label", "event", payload) |
Emit to specific window |
JS/TS API (@tauri-apps/api) |
Purpose |
|---|---|
invoke('cmd', { args }) |
Call a Rust command |
listen('event', handler) |
Listen for backend events |
emit('event', payload) |
Emit event to backend |
Channel<T> |
Receive streamed data from Rust |
SvelteKit Setup Essentials
// svelte.config.js
import adapter from '@sveltejs/adapter-static';
export default { kit: { adapter: adapter({ fallback: 'index.html' }) } };
// src/routes/+layout.ts
export const ssr = false;
// tauri.conf.json
{
"build": {
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build",
"devUrl": "http://localhost:5173",
"frontendDist": "../build"
}
}
Security Model (Capability-Based)
Permissions (TOML) â Capabilities (JSON/TOML) â Runtime Authority
what ops bind to windows enforce at runtime
- Frontend is untrusted by default â all backend access requires explicit capability grants
- Commands must be listed in capability files to be callable from JS
- Scopes (allow/deny) provide fine-grained resource boundaries
- Isolation pattern adds AES-GCM encrypted IPC for high-security apps
Release Build Optimization
# src-tauri/Cargo.toml
[profile.release]
codegen-units = 1
lto = true
opt-level = "s"
panic = "abort"
strip = true
References
- Getting Started & SvelteKit â project creation, SvelteKit adapter-static setup, project structure
- Architecture & Process Model â multi-process design, WRY/TAO, crate ecosystem, size optimization
- Inter-Process Communication â commands, events, channels, brownfield vs isolation patterns
- Security & Permissions â capabilities, permissions, scopes, CSP, security lifecycle
- Commands & Events â calling Rust from frontend, calling frontend from Rust, streaming
- Development & Configuration â config files, resources, state management, icons, dev workflow
- Testing â IPC mocking, event mocking, window mocking, WebDriver, tauri-driver