Build Native Desktop Apps with Tauri 2.0: A Step‑by‑Step Guide for Web Developers

This tutorial walks web developers through using Tauri 2.0 to create a native macOS desktop application, covering installation, project scaffolding, core HTML/JS code, Rust command integration, configuration, building, packaging, and a final assessment of Tauri's advantages over Electron.

21CTO
21CTO
21CTO
Build Native Desktop Apps with Tauri 2.0: A Step‑by‑Step Guide for Web Developers

In this article we revisit Tauri, the framework that lets you combine any front‑end library with a Rust core to create native desktop applications.

Using the Tauri 2.0 beta we walk through creating a simple macOS UI app, from installing the toolkit to running the generated template.

We show the default project structure, where Tauri acts as a static web host and bundles the web assets with a small native executable.

After installing the latest version we run a one‑line command to scaffold a new project, choose a JavaScript front‑end (the Rust backend is optional), and let the tool download the required dependencies.

We then examine the generated index.html file, which contains a basic page with a greeting form, and the accompanying main.js that uses window.__TAURI__.core.invoke to call a Rust command.

const { invoke } = window.__TAURI__.core;
let greetInputEl;
let greetMsgEl;
async function greet() {
  greetMsgEl.textContent = await invoke("greet", { name: greetInputEl.value });
}
window.addEventListener("DOMContentLoaded", () => {
  greetInputEl = document.querySelector("#greet-input");
  greetMsgEl = document.querySelector("#greet-msg");
  document.querySelector("#greet-form").addEventListener("submit", (e) => {
    e.preventDefault();
    greet();
  });
});

The Rust side defines the greet command that formats a friendly message:

#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}
fn main() {
    tauri::Builder::default()
        .plugin(tauri_plugin_shell::init())
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

The configuration file tauri.conf.json defines the product name, window size, and bundle options for macOS.

{
  "productName": "thenewstack",
  "version": "0.0.0",
  "identifier": "com.tauri.dev",
  "build": { "frontendDist": "../src" },
  "app": { "withGlobalTauri": true, "windows": [{ "title": "thenewstack", "width": 800, "height": 600 }] },
  "bundle": { "active": true, "targets": "all", "icon": ["icons/32x32.png", "icons/128x128.png"] }
}

Running tauri dev builds the Rust backend, packages the web assets, and launches the app, producing a ~10 MB dmg that can be moved to the Applications folder.

Overall, Tauri offers a lightweight, secure alternative to Electron, allowing web developers to create native desktop apps without sacrificing performance.

Conclusion

While the flexibility of supporting many JavaScript frameworks adds complexity, the combination of Rust safety and familiar web tooling makes Tauri a compelling choice for rapid desktop‑app development.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

TauriWeb Developmenttutorialdesktop applications
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.