假设已经安装好rust和node.js环境
npm create tauri-app@latest
或者
pnpm create tauri-app
pnpm install
vscode插件
Tauri
ubuntu前置条件
bash
sudo apt update
sudo apt install libwebkit2gtk-4.1-dev \
build-essential \
curl \
wget \
file \
libxdo-dev \
libssl-dev \
libayatana-appindicator3-dev \
librsvg2-dev
运行命令
npm run tauri dev
或者
pnpm tauri dev
构建
pnpm tauri build --no-bundle 构建直接运行程序
pnpm tauri build # 出安装包
pnpm tauri build --debug # 带调试
构建产物:
src-tauri/target/release/bundle/nsis/ 安装包
src-tauri/target/release/ 免安装包
修改端口
同时改
src-tauri\tauri.conf.json
vite.config.ts
windows AI 改完调试
windows版放置两个文件:test\ai-check.ps1
powershell
$repoRoot = Split-Path $PSScriptRoot -Parent
Set-Location $repoRoot
$script:failed = @()
function Invoke-Step {
param([string]$Name, [scriptblock]$Block)
Write-Host ""
Write-Host "=== $Name ===" -ForegroundColor Cyan
& $Block
if ($LASTEXITCODE -ne 0) {
$script:failed += "$Name (exit $LASTEXITCODE)"
}
}
# === 前端: typecheck ===
Invoke-Step "frontend: typecheck" { pnpm exec tsc -b --noEmit }
# === 前端: lint ===
Invoke-Step "frontend: lint" { pnpm lint }
# === 后端: clippy ===
Invoke-Step "backend: clippy" {
Push-Location (Join-Path $repoRoot 'src-tauri')
try { cargo clippy --workspace --all-targets --message-format=short -- -D warnings }
finally { Pop-Location }
}
# === 汇总 ===
Write-Host ""
Write-Host "=== Summary ===" -ForegroundColor Yellow
if ($script:failed.Count -eq 0) {
Write-Host "All checks passed." -ForegroundColor Green
exit 0
} else {
Write-Host "Failed steps:" -ForegroundColor Red
$script:failed | ForEach-Object { Write-Host " - $_" -ForegroundColor Red }
exit 1
}
test\ai-verify.ps1
powershell
$repoRoot = Split-Path $PSScriptRoot -Parent
Set-Location $repoRoot
$script:failed = @()
function Invoke-Step {
param([string]$Name, [scriptblock]$Block)
Write-Host ""
Write-Host "=== $Name ===" -ForegroundColor Cyan
& $Block
if ($LASTEXITCODE -ne 0) {
$script:failed += "$Name (exit $LASTEXITCODE)"
}
}
# === 前端: typecheck ===
Invoke-Step "frontend: typecheck" { pnpm exec tsc -b --noEmit }
# === 前端: lint ===
Invoke-Step "frontend: lint" { pnpm lint }
# === 前端: 测试(如果有) ===
Invoke-Step "frontend: test" { pnpm run --if-present test }
# === 后端: clippy ===
Invoke-Step "backend: clippy" {
Push-Location (Join-Path $repoRoot 'src-tauri')
try { cargo clippy --workspace --all-targets --message-format=short -- -D warnings }
finally { Pop-Location }
}
# === 后端: test ===
Invoke-Step "backend: test" {
Push-Location (Join-Path $repoRoot 'src-tauri')
try { cargo test --workspace }
finally { Pop-Location }
}
# === 汇总 ===
Write-Host ""
Write-Host "=== Summary ===" -ForegroundColor Yellow
if ($script:failed.Count -eq 0) {
Write-Host "All checks passed." -ForegroundColor Green
exit 0
} else {
Write-Host "Failed steps:" -ForegroundColor Red
$script:failed | ForEach-Object { Write-Host " - $_" -ForegroundColor Red }
exit 1
}
windows提示词
markdown
## 自检规则
### 触发时机
- 每次修改前端或 Rust 代码后,立即运行 `.\test\ai-check.ps1`
- 完成功能切片后,运行 `.\test\ai-verify.ps1`
### 失败处理
- 退出码非零必须先修复才能继续
- 同一错误连续 3 次仍失败必须停下来向用户求助
- 禁止注释代码、删测试、加 `#[allow(...)]` 或 `// @ts-ignore` 绕过错误
linux AI改完调试
test/ai-check.sh
bash
#!/usr/bin/env bash
set -uo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)"
readonly CYAN=$'\033[36m'
readonly YELLOW=$'\033[33m'
readonly GREEN=$'\033[32m'
readonly RED=$'\033[31m'
readonly RESET=$'\033[0m'
failed=()
run_step() {
local name="$1"
shift
printf '\n%s=== %s ===%s\n' "$CYAN" "$name" "$RESET"
"$@"
local status=$?
if (( status != 0 )); then
failed+=("$name (exit $status)")
fi
}
frontend_typecheck() {
pnpm exec tsc -b --noEmit
}
frontend_lint() {
pnpm lint
}
backend_clippy() {
(
cd "$REPO_ROOT/src-tauri" &&
cargo clippy --workspace --all-targets --message-format=short -- -D warnings
)
}
cd "$REPO_ROOT"
run_step "frontend: typecheck" frontend_typecheck
run_step "frontend: lint" frontend_lint
run_step "backend: clippy" backend_clippy
printf '\n%s=== Summary ===%s\n' "$YELLOW" "$RESET"
if (( ${#failed[@]} == 0 )); then
printf '%sAll checks passed.%s\n' "$GREEN" "$RESET"
exit 0
fi
printf '%sFailed steps:%s\n' "$RED" "$RESET"
for step in "${failed[@]}"; do
printf '%s - %s%s\n' "$RED" "$step" "$RESET"
done
exit 1
test/ai-verify.sh
bash
#!/usr/bin/env bash
set -uo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)"
readonly CYAN=$'\033[36m'
readonly YELLOW=$'\033[33m'
readonly GREEN=$'\033[32m'
readonly RED=$'\033[31m'
readonly RESET=$'\033[0m'
failed=()
run_step() {
local name="$1"
shift
printf '\n%s=== %s ===%s\n' "$CYAN" "$name" "$RESET"
"$@"
local status=$?
if (( status != 0 )); then
failed+=("$name (exit $status)")
fi
}
frontend_typecheck() {
pnpm exec tsc -b --noEmit
}
frontend_lint() {
pnpm lint
}
frontend_test() {
pnpm run --if-present test
}
backend_clippy() {
(
cd "$REPO_ROOT/src-tauri" &&
cargo clippy --workspace --all-targets --message-format=short -- -D warnings
)
}
backend_test() {
(
cd "$REPO_ROOT/src-tauri" &&
cargo test --workspace
)
}
cd "$REPO_ROOT"
run_step "frontend: typecheck" frontend_typecheck
run_step "frontend: lint" frontend_lint
run_step "frontend: test" frontend_test
run_step "backend: clippy" backend_clippy
run_step "backend: test" backend_test
printf '\n%s=== Summary ===%s\n' "$YELLOW" "$RESET"
if (( ${#failed[@]} == 0 )); then
printf '%sAll checks passed.%s\n' "$GREEN" "$RESET"
exit 0
fi
printf '%sFailed steps:%s\n' "$RED" "$RESET"
for step in "${failed[@]}"; do
printf '%s - %s%s\n' "$RED" "$step" "$RESET"
done
exit 1
linux提示词
markdown
## 自检规则
### 触发时机
- 每次修改前端或 Rust 代码后,立即运行 `./test\ai-check.sh`
- 完成功能切片后,运行 `./test/ai-verify.sh`
### 失败处理
- 退出码非零必须先修复才能继续
- 同一错误连续 3 次仍失败必须停下来向用户求助
- 禁止注释代码、删测试、加 `#[allow(...)]` 或 `// @ts-ignore` 绕过错误
设置应用名称和窗口标题
src-tauri/tauri.conf.json
json
{
"productName": "我的应用",
"version": "0.1.0",
"identifier": "com.example.myapp",
"app": {
"windows": [
{
"title": "我的应用",
"width": 800,
"height": 600
}
]
},
"bundle": {
"active": true,
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}