pub fn plugin_config<T: DeserializeOwned>(name: &str) -> Option<T>build only.Expand description
Reads the configuration of the plugin with the given name from the environment.
Tauri applications configure plugins through the plugins > $plugin-name object of their
tauri.conf.json. The Tauri CLI forwards that object to the build script of the plugin
through the TAURI_<PLUGIN_NAME>_PLUGIN_CONFIG environment variable (uppercased, with -
replaced by _), so plugins can generate platform-specific files from it - for example
adding a usage description to the iOS Info.plist with mobile::update_info_plist
(macOS hosts only).
Returns None when the variable is not set, which is the case when the crate is built
without the Tauri CLI (e.g. a plain cargo build), so the build script must always be able
to run without a configuration.
Also emits a cargo:rerun-if-env-changed instruction for the variable.
§Examples
// usually a type deriving `serde::Deserialize`
let config = tauri_plugin::plugin_config::<serde_json::Value>("my-plugin");
let timeout = config
.and_then(|c| c.get("timeout").and_then(|t| t.as_u64()))
.unwrap_or(30);§Panics
Panics if the value of the environment variable is not a valid JSON representation of T,
which means the plugin configuration on the app’s tauri.conf.json does not match the
expected format.