Skip to content
Tauri
Releases

Localhost

GitHub crates.io
API Reference

Expose your app’s assets through a localhost server instead of the default custom protocol.

  • Windows
  • Linux
  • macOS

This plugin requires a Rust version of at least 1.75

  1. Install the localhost plugin by adding the following to your Cargo.toml file:

    src-tauri/Cargo.toml
    [dependencies]
    tauri-plugin-localhost = "2.0.0-beta"
    # alternatively with Git:
    tauri-plugin-localhost = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
  2. Modify lib.rs to initialize the plugin:

    src-tauri/src/lib.rs
    fn run() {
    tauri::Builder::default()
    .plugin(tauri_plugin_localhost::Builder::new().build())
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
    }

The localhost plugin is available in Rust.

src-tauri/src/lib.rs
use tauri::{webview::WebviewWindowBuilder, WebviewUrl};
fn run() {
let port: u16 = 9527;
tauri::Builder::default()
.plugin(tauri_plugin_localhost::Builder::new(port).build())
.setup(move |app| {
let url = format!("http://localhost:{}", port).parse().unwrap();
WebviewWindowBuilder::new(app, "main".to_string(), WebviewUrl::External(url))
.title("Localhost Example")
.build()?;
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

© 2024 Tauri Contributors. CC-BY / MIT