Tauri
Add the Rust plugin to an existing Tauri 2 app, run the frontend through a proxy, and switch to a builtin bundle. This guide covers desktop apps, with mobile packaging differences at the end.
Before you begin
Prepare a working Tauri 2 project, Rust 1.90 or later, and a Node.js version
supported by @wvb/cli: 20.19 or later in the 20.x line, or 22.12 or later. Put
the frontend in web. Follow the
Tauri prerequisites for your
operating system.
Use the following file layout:
1. Install dependencies
Add the dependency to src-tauri/Cargo.toml:
[dependencies]
wvb-tauri = "0.3"2. Initialize the plugin and connect the development server
Register a proxy for the bundle scheme on the Tauri builder:
use wvb_tauri::{Config, ProtocolConfig, wvb::protocol::ProxyResolver};
fn main() {
let hosts = ProxyResolver::host_mapping([
("app.wvb", "http://localhost:5173"),
]);
tauri::Builder::default()
.plugin(wvb_tauri::init(
Config::new().protocol(ProtocolConfig::proxy("bundle", hosts)),
))
.run(tauri::generate_context!())
.expect("failed to run app");
}If your project has src/lib.rs, register the plugin on the builder in your
existing run() function. Set the main window URL in tauri.conf.json:
{
"app": {
"windows": [{ "label": "main", "url": "bundle://app.wvb/" }]
}
}Merge this snippet into your existing configuration. Start the frontend server
at http://localhost:5173, then run the Tauri app and check that the page
loads.
3. Install the CLI
Install the CLI at the project root:
npm install --save-dev @wvb/cli4. Install the local build as a builtin bundle
Configure the web workspace to package its dist directory as bundle app,
version 1.0.0:
import { defineConfig } from '@wvb/cli';
export default defineConfig({
pack: { srcDir: './dist' },
remote: { bundleName: 'app', version: '1.0.0' },
});At the native project root, point builtin.target at the web workspace:
import { defineConfig } from '@wvb/cli';
export default defineConfig({
builtin: {
outDir: './src-tauri/bundles',
target: { type: 'local', workspaces: ['./web'] },
},
});Run your existing frontend build command. After web/dist/index.html is
created, run the following command from the native project root:
yarn wvb builtinThe CLI packages the web build output and creates
./src-tauri/bundles/manifest.json and ./src-tauri/bundles/app/1.0.0.wvb.
Add a resource mapping to tauri.conf.json:
{
"bundle": {
"resources": { "bundles/": "bundles/" }
}
}5. Run and verify the builtin bundle
Remove the proxy host mapping and replace the plugin configuration as follows:
use wvb_tauri::{Config, ProtocolConfig, wvb::protocol::ProxyResolver};
fn main() {
let hosts = ProxyResolver::host_mapping([
("app.wvb", "http://localhost:5173"),
]);
tauri::Builder::default()
.plugin(wvb_tauri::init(
Config::new().protocol(ProtocolConfig::proxy("bundle", hosts)),
Config::new().protocol(ProtocolConfig::bundle("bundle")),
))
.run(tauri::generate_context!())
.expect("failed to run app");
}Stop the frontend server and rebuild the native app with your existing Tauri
command. The page should load at bundle://app.wvb/. The packaged resources
must contain bundles/manifest.json and bundles/app/1.0.0.wvb.
Mobile packaging
Android support requires
tauri-plugin-fs. Add the
dependency to Cargo.toml:
[dependencies]
tauri-plugin-fs = "2"Register tauri_plugin_fs::init() before wvb_tauri::init():
use wvb_tauri::{Config, ProtocolConfig, wvb::protocol::ProxyResolver};
fn main() {
tauri::Builder::default()
.plugin(tauri_plugin_fs::init())
.plugin(wvb_tauri::init(/* */))
.run(tauri::generate_context!())
.expect("failed to run app");
}