Skip to content

Disable for Production

A possible setup to disable devtools in production using Rusts cfg macros

Rusts cfg macros can be used to conditionally disable or enable code. In the following snippet we use them to disable the devtools code in non-debug builds, i.e. when you build for production through cargo tauri build or cargo build --release.

fn main() {
#[cfg(debug_assertions)]
let devtools = devtools::init(); // initialize the plugin as early as possible
let mut builder = tauri::Builder::default();
#[cfg(debug_assertions)]
{
builder = builder.plugin(devtools); // then register it with Tauri
}
builder.run(tauri::generate_context!("./tauri.conf.json"))
.expect("error while running tauri application");
}