乐闻世界logo
搜索文章和话题

What is the build and packaging process for Tauri applications

2月19日 19:24

The build and packaging process for Tauri applications involves multiple steps, here is a detailed explanation:

1. Development Environment Setup

Install Dependencies

bash
# Install Rust curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh # Install Node.js and package manager # Install system dependencies (macOS) xcode-select --install # Install system dependencies (Linux) sudo apt update sudo apt install libwebkit2gtk-4.0-dev \ build-essential \ curl \ wget \ file \ libssl-dev \ libayatana-appindicator3-dev \ librsvg2-dev

Install Tauri CLI

bash
cargo install tauri-cli

2. Project Configuration

tauri.conf.json Configuration

json
{ "build": { "beforeDevCommand": "npm run dev", "beforeBuildCommand": "npm run build", "devPath": "http://localhost:1420", "distDir": "../dist", "withGlobalTauri": false }, "package": { "productName": "MyApp", "version": "1.0.0" }, "tauri": { "bundle": { "identifier": "com.example.myapp", "icon": ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"], "targets": ["dmg", "msi", "appimage"], "category": "Developer Tool" } } }

3. Development Mode

bash
npm run tauri dev

This command will:

  1. Run beforeDevCommand to start the development server
  2. Compile Rust code
  3. Start the application and connect to the development server
  4. Support hot reload

4. Build Production Version

Basic Build

bash
npm run tauri build

Build process:

  1. Run beforeBuildCommand to build frontend resources
  2. Compile Rust code to binary files
  3. Package frontend resources into the application
  4. Generate platform-specific installation packages

Build for Specific Platform

bash
# macOS npm run tauri build -- --target universal-apple-darwin # Windows npm run tauri build -- --target x86_64-pc-windows-msvc # Linux npm run tauri build -- --target x86_64-unknown-linux-gnu

5. Packaging Options

macOS Packaging

json
{ "bundle": { "targets": ["dmg", "app"], "macOS": { "signingIdentity": "Developer ID Application: Your Name", "entitlements": "entitlements.plist", "hardenedRuntime": true, "minimumSystemVersion": "10.13" } } }

Windows Packaging

json
{ "bundle": { "targets": ["msi", "nsis"], "windows": { "certificateThumbprint": "YOUR_CERTIFICATE_THUMBPRINT", "digestAlgorithm": "sha256", "timestampUrl": "http://timestamp.digicert.com" } } }

Linux Packaging

json
{ "bundle": { "targets": ["appimage", "deb"], "linux": { "deb": { "depends": ["libwebkit2gtk-4.0-37"] } } } }

6. Code Signing

macOS Signing

bash
# Import certificate security import certificate.p12 -k ~/Library/Keychains/login.keychain # Auto-signing (set in configuration)

Windows Signing

bash
# Use signtool signtool sign /f certificate.pfx /p password /t http://timestamp.digicert.com app.exe

7. Release Process

GitHub Actions Automation

yaml
name: Release on: push: tags: - 'v*' jobs: release: strategy: matrix: os: [macos-latest, ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 - uses: dtolnay/rust-toolchain@stable - run: npm install - run: npm run tauri build - uses: softprops/action-gh-release@v1 with: files: src-tauri/target/release/bundle/*

8. Build Optimization

Reduce Package Size

toml
[profile.release] opt-level = "z" lto = true codegen-units = 1 strip = true

Parallel Build

bash
cargo build --release -j $(nproc)

9. Common Issues

Build Failure

  • Check if system dependencies are complete
  • Confirm Rust and Node.js version compatibility
  • View detailed error logs

Signing Issues

  • Ensure certificate is valid
  • Check signing configuration
  • Verify timestamp server availability

Cross-Platform Build

  • Use GitHub Actions or CI/CD
  • Configure different build targets
  • Test platform compatibility
标签:Tauri