tauri-docs
tauri-docs copied to clipboard
Add guide: Conditional compilation
TODO
Tauri exposes several environment variables to the beforeDevCommand and beforeBuildCommand, allowing frontend bundlers to perform conditional compilation. You can use this to write platform-specific JS code.
Details
JavaScript
-
only available with some bundlers (but most) -> called treeshaking
-
the cli exposes a set of environment variables
TAURI_PLATFORM- same astarget_osTAURI_ARCH- same astarget_archTAURI_FAMILY- same astarget_familyTAURI_PLATFORM_VERSION- version of the OSTAURI_PLATFORM_TYPE-"Linux" | "Darwin" | "Window_NT"same as nodejsos.type()TAURI_DEBUG- same asdebug_assertions
-
quick example
Rust
- link to conditional compilation guide https://doc.rust-lang.org/reference/conditional-compilation.html
- quick intro
cfg!and#[cfg()] - quick intro features
- target a specific OS (
target_osandtarget_family) - target a specific CPU architecture
cfg(debug_assertions)
We definitely need a guide on this one way or another, possibly under the Develop guide section. Tracking for 2.0.