MudEngine Part 10: Desktop with Blitz
Swap the import and launch
The core change is in src/main.rs: one binary, three build targets.
dx serve compiles the Axum server binary (feature server) on the host, and the web client as WASM (feature web, no server). Your main.rs is compiled for both of those — plus a third build, the native client you run with cargo run (host, no server feature).
Because main.rs is shared, each launch must be chosen with cfg. The rule that makes it work is in Cargo.toml above: dioxus-native is gated out of the WASM build, so the native window code can never compile for the web target.
Your components don't change at all — src/components/app.rs keeps use dioxus::prelude::*;. Only the entry point gains three arms. Open src/main.rs:
mod components; mod game; use crate::components::app::App; // The native client is a separate process: it connects to the Axum server // started by `dx serve` instead of bundling its own server. #[cfg(all(not(feature = "server"), not(target_arch = "wasm32")))] use dioxus::fullstack::set_server_url; #[cfg(all(not(feature = "server"), not(target_arch = "wasm32")))] use dioxus_native::{Config, LogicalSize, WindowAttributes}; fn main() { // Server binary (dx serve → cargo feature `server`): render the SSR page // and serve the WebSocket. #[cfg(feature = "server")] dioxus::launch(App); // Web client (dx serve → wasm target, feature `web`): same origin as the // server, so no `set_server_url` — hydration makes the SSR page live. #[cfg(all(not(feature = "server"), target_arch = "wasm32"))] dioxus::launch(App); // Native client (cargo run): point fullstack at the `dx serve` server and // open a Blitz window (WGPU/Vello) instead of a browser tab. #[cfg(all(not(feature = "server"), not(target_arch = "wasm32")))] { set_server_url("http://localhost:8080"); let cfg = Config::new().with_window_attributes( WindowAttributes::default() .with_title("MudEngine") .with_inner_size(LogicalSize::new(1024.0, 768.0)), ); dioxus_native::launch_cfg(App, vec![], vec![Box::new(cfg)]); } }
The three arms of main.rs:
- Server binary —
#[cfg(feature = "server")]:dioxus::launch(App)renders the SSR page and serves the WebSocket. - Web client —
#[cfg(all(not(feature = "server"), target_arch = "wasm32"))]:dioxus::launch(App)hydrates the SSR page in the browser. Noset_server_url— the browser origin is the server. - Native client —
#[cfg(all(not(feature = "server"), not(target_arch = "wasm32")))]:set_server_url("http://localhost:8080")points fullstack at thedx serveserver, thendioxus_native::launch_cfg(...)opens the Blitz window.
The set_server_url and dioxus_native::{...} imports carry the same cfg guard, so the web and server targets never see them.
There is no dioxus_native::prelude swap in this project. The components in src/components/ keep use dioxus::prelude::*; and everything from Part 9 — rsx!, use_signal, use_resource, #[component], Key — works unchanged, because dioxus-native shares the same dioxus-core, dioxus-signals, and dioxus-hooks types.
main.rs never imports a prelude at all; it only needs the window-config types (Config, LogicalSize, WindowAttributes) straight from dioxus_native.