Configuration Files
Since Tauri is a toolkit for building applications there can be many files to configure project settings. Some common files that you may run across are tauri.conf.json
, package.json
and Cargo.toml
. We briefly explain each on this page to help point you in the right direction for which files to modify.
Tauri Config
The Tauri configuration is used to define the source of your Web app, describe your application’s metadata, configure bundles, set plugin configurations, modify runtime behavior by configuring windows, tray icons, menus and more.
This file is used by the Tauri runtime and the Tauri CLI. You can define build settings (such as the command run before tauri build
or tauri dev
kicks in), set the name and version of your app, control the Tauri runtime, and configure plugins. You can find all of the options in the configuration reference.
Supported Formats
The default Tauri config format is JSON. The JSON5 or TOML format can be enabled by adding the config-json5
or config-toml
feature flag (respectively) to the tauri
and tauri-build
dependencies in Cargo.toml
.
[build-dependencies]tauri-build = { version = "2.0.0-rc", features = [ "config-json5" ] }
[dependencies]tauri = { version = "2.0.0-rc", features = [ "config-json5" ] }
The structure and values are the same across all formats, however, the formatting should be consistent with the respective file’s format:
{ build: { devUrl: "http://localhost:3000", // start the dev server beforeDevCommand: "npm run dev" }, bundle: { active: true, icon: ["icons/app.png"] } app: { windows: [{ title: "MyApp" }] }, plugins: { updater: { pubkey: "updater pub key", endpoints: ["https://my.app.updater/{{target}}/{{current_version}}"] } }}
[build]dev-url = "http://localhost:3000"# start the dev serverbefore-dev-command = "npm run dev"
[bundle]active = trueicon = ["icons/app.png"]
[[app.windows]]title = "MyApp"
[plugins.updater]pubkey = "updater pub key"endpoints = ["https://my.app.updater/{{target}}/{{current_version}}"]
Note that JSON5 and TOML supports comments, and TOML can use kebab-case for config names which are more idiomatic.
Cargo.toml
Cargo’s manifest file is used to declare Rust crates your app depends on, metadata about your app, and other Rust-related features. If you do not intend to do backend development using Rust for your app then you may not be modifying it much, but it’s important to know that it exists and what it does.
Below is an example of a barebones Cargo.toml
file for a Tauri project:
[package]name = "app"version = "0.1.0"description = "A Tauri App"authors = ["you"]license = ""repository = ""default-run = "app"edition = "2021"rust-version = "1.57"
[build-dependencies]tauri-build = { version = "2.0.0-rc" }
[dependencies]serde_json = "1.0"serde = { version = "1.0", features = ["derive"] }tauri = { version = "2.0.0-rc", features = [ ] }
The most important parts to take note of are the tauri-build
and tauri
dependencies. Generally, they must both be on the latest minor versions as the Tauri CLI, but this is not strictly required. If you encounter issues while trying to run your app you should check that any Tauri versions (tauri
and tauri-cli
) are on the latest versions for their respective minor releases.
Cargo version numbers use Semantic Versioning. Running cargo update
in the src-tauri
folder will pull the latest available Semver-compatible versions of all dependencies. For example, if you specify 2.0.0-rc
as the version for tauri-build
, Cargo will detect and download version 2.0.0-rc.0
because it is the latest Semver-compatible version available. Tauri will update the major version number whenever a breaking change is introduced, meaning you should always be capable of safely upgrading to the latest minor and patch versions without fear of your code breaking.
If you want to use a specific crate version you can use exact versions instead by prepending =
to the version number of the dependency:
tauri-build = { version = "=2.0.0-rc.0" }
An additional thing to take note of is the features=[]
portion of the tauri
dependency. Running tauri dev
and tauri build
will automatically manage which features need to be enabled in your project based on the your Tauri configuration. For more information about tauri
feature flags see the documentation.
When you build your application a Cargo.lock
file is produced. This file is used primarily for ensuring that the same dependencies are used across machines during development (similar to yarn.lock
, pnpm-lock.yaml
or package-lock.json
in Node.js). It is recommended to commit this file to your source repository so you get consistent builds.
To learn more about the Cargo manifest file please refer to the official documentation.
package.json
This is the package file used by Node.js. If the frontend of your Tauri app is developed using Node.js-based technologies (such as npm
, yarn
, or pnpm
) this file is used to configure the frontend dependencies and scripts.
An example of a barebones package.json
file for a Tauri project might look a little something like this:
{ "scripts": { "dev": "command to start your app development mode", "build": "command to build your app frontend", "tauri": "tauri" }, "dependencies": { "@tauri-apps/api": "^2.0.0-rc.0", "@tauri-apps/cli": "^2.0.0-rc.0" }}
It’s common to use the "scripts"
section to store the commands used to launch and build the frontend used by your Tauri application. The above package.json
file specifies the dev
command that you can run using yarn dev
or npm run dev
to start the frontend framework and the build
command that you can run using yarn build
or npm run build
to build your frontend’s Web assets to be added by Tauri in production. The most convenient way to use these scripts is to hook them with the Tauri CLI via the Tauri configuration’s beforeDevCommand and beforeBuildCommand hooks:
{ "build": { "beforeDevCommand": "yarn dev", "beforeBuildCommand": "yarn build" }}
The dependencies object specifies which dependencies Node.js should download when you run either yarn
, pnpm install
or npm install
(in this case the Tauri CLI and API).
In addition to the package.json
file you may see either a yarn.lock
, pnpm-lock.yaml
or package-lock.json
file. These files assist in ensuring that when you download the dependencies later you’ll get the exact same versions that you have used during development (similar to Cargo.lock
in Rust).
To learn more about the package.json
file format please refer to the official documentation.
© 2024 Tauri Contributors. CC-BY / MIT