Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 39 ยท Architecture and Setup

Configuration Files: tauri.conf.json and Cargo.toml

Configure a Tauri 2 app: productName, identifier, build commands, windows, security CSP, bundle settings, platform overrides and Cargo features, with a validator.

A Tauri app is configured in two places: tauri.conf.json for the app itself (name, windows, build commands, bundle) and Cargo.toml for the Rust crate (dependencies and features). This lesson reads both closely.

tauri.conf.json

Here is a realistic configuration:

JSON
{
  "$schema": "https://schema.tauri.app/config/2",
  "productName": "hello-tauri",
  "version": "0.1.0",
  "identifier": "com.example.hello-tauri",
  "build": {
    "beforeDevCommand": "npm run dev",
    "devUrl": "http://localhost:1420",
    "beforeBuildCommand": "npm run build",
    "frontendDist": "../dist"
  },
  "app": {
    "windows": [
      { "title": "Hello Tauri", "width": 900, "height": 640 }
    ],
    "security": {
      "csp": "default-src 'self'; img-src 'self' data:"
    }
  },
  "bundle": {
    "active": true,
    "targets": "all",
    "icon": ["icons/32x32.png", "icons/128x128.png", "icons/icon.icns", "icons/icon.ico"]
  }
}

Top-level keys

  • productName: the name users see (window title default, installer name, start menu entry).
  • version: your app version. It may be a semver string or a path to a package.json file.
  • identifier: the reverse-domain id. It also decides where the app stores its data folder.
  • $schema: gives your editor autocomplete and validation.

build

  • beforeDevCommand starts your frontend dev server for tauri dev.
  • devUrl is the address the webview loads in dev mode.
  • beforeBuildCommand produces the static frontend for release.
  • frontendDist is the folder of built files, relative to src-tauri, that will be embedded.

If you use no bundler (just static HTML), you may set frontendDist to the folder holding your index.html and skip the commands.

app

  • windows lists windows created at startup. Each has a label (defaults to main), title, width, height, resizable, fullscreen, decorations, url and more. You can also create windows from code; see Windows.
  • security.csp sets the Content Security Policy, a header-like rule restricting what the page may load. The scaffold may start with null (no policy) for convenience; set a real one before you ship.
  • withGlobalTauri exposes window.__TAURI__ for apps without a bundler. Leave it off if you import the API as modules.

bundle

  • active turns bundling on.
  • targets chooses installer formats: "all" or a list like ["nsis", "msi", "dmg", "deb", "appimage"].
  • icon lists icon files.
  • Extra keys cover resources (extra files to ship), copyright, category, shortDescription, windows/macOS/linux sections and createUpdaterArtifacts.

plugins

A plugins object holds per-plugin options, for example the updater's public key and endpoints.

Platform-specific files

Tauri merges extra files next to the main one: tauri.windows.conf.json, tauri.macos.conf.json, tauri.linux.conf.json, tauri.android.conf.json and tauri.ios.conf.json. A matching file is merged over the base config (objects merge, arrays are replaced). Use them for settings that differ per platform, like a different icon list or window size.

You can also merge a one-off file from the command line: npm run tauri dev -- --config src-tauri/tauri.beta.conf.json.

Cargo.toml

TOML
[package]
name = "hello-tauri"
version = "0.1.0"
edition = "2021"

[build-dependencies]
tauri-build = { version = "2", features = [] }

[dependencies]
tauri = { version = "2", features = ["tray-icon"] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[profile.release]
codegen-units = 1
lto = true
opt-level = "s"
panic = "abort"
strip = true
  • tauri features enable optional parts, like tray-icon for system tray support or devtools to allow the inspector in release builds. Tauri 2 trimmed the old "allowlist" features; permissions now live in capability files.
  • The versions must stay in step: the tauri crate and the JavaScript @tauri-apps/api should be on the same minor version, as should plugin crates and their npm twins. The CLI warns about mismatches in tauri info.
  • [profile.release] options shrink and speed up the binary: lto (link-time optimization), opt-level = "s" (optimize for size), panic = "abort" (smaller, no unwinding) and strip (remove symbols). The cost is a slower release compile.

Changing Cargo.toml features or tauri.conf.json requires restarting tauri dev. Config is read at startup and embedded at compile time.

Try it: a config checker (stand-in)

Typos in config cause confusing failures. This stand-in checks a config object for the most common mistakes, the way you might add a quick CI step.

Node.js Stand-in: lint a tauri.conf.json

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Try it: platform overrides merge (stand-in)

The merge rule is "objects merge, arrays replace". This stand-in implements it so you can predict what a platform file does.

Node.js Stand-in: merge a platform override

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The csp survives (objects merge), but windows and icon are replaced as whole arrays.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which key holds the folder of built frontend files that gets embedded?

    frontendDist points to the built static files, relative to src-tauri.
  2. 2. How does a tauri.windows.conf.json file combine with the base config?

    Objects merge key by key, while arrays in the override replace the base arrays.
  3. 3. What is the Cargo feature 'tray-icon' for?

    Optional Tauri capabilities such as the tray are switched on with Cargo features.
  4. 4. When must you restart tauri dev?

    Config is read at startup and embedded at compile time; CSS changes hot-reload.

Summary

  • tauri.conf.json sets the product name, identifier, build commands, windows, CSP and bundle options.
  • Platform files like tauri.windows.conf.json merge over the base: objects merge, arrays replace.
  • Cargo.toml lists dependencies, Tauri features and the release profile.
  • Keep tauri, plugin crates and their npm packages on matching versions.
  • Set a real CSP before shipping and restart dev after config changes.

Next: Frontend frameworks and bundlers