Trunk
By the Trunk-rs open-source project
Trunk is an open-source build tool and bundler for Rust WebAssembly applications, handling compilation, asset bundling, and a local development server so developers can build and iterate on Rust-based frontends without hand-writing custom…
Definition
Trunk is an open-source build tool and bundler for Rust WebAssembly applications, handling compilation, asset bundling, and a local development server so developers can build and iterate on Rust-based frontends without hand-writing custom build scripts. It fills a role similar to webpack or Vite, but scoped specifically to the Rust-to-WebAssembly workflow across multiple competing UI frameworks and toolchains that target the browser.
Overview
Trunk was created to solve a practical gap in the Rust WebAssembly ecosystem: compiling Rust to WebAssembly with tools like wasm-bindgen produces raw output that still needs to be wired into an HTML page, bundled together with CSS and static assets, and served during local development, and doing this by hand with shell scripts was a common source of friction for early Rust web developers. Trunk automates that entire pipeline behind a single configuration file and one command-line tool. Mechanically, Trunk reads an index.html file annotated with special link tags that tell it which Rust crate to compile to WebAssembly, which Sass or CSS files to process, and which static assets to copy into the output directory. Running trunk serve compiles the project, bundles the resulting WebAssembly module and its JavaScript glue code, injects the necessary script tags into the HTML, and serves everything through a local development server with automatic rebuilding on file changes as they are saved. Running trunk build produces an optimized, production-ready output directory that can be deployed straight to any static file host without any further manual processing. Within the broader Rust WebAssembly tooling landscape, Trunk is largely framework-agnostic, working with Yew, Leptos, Sycamore, Dioxus, and various other Rust UI frameworks that compile to WebAssembly, rather than being tied to any single one of them. This distinguishes it from framework-specific tooling and positions it closer to how Vite or webpack serve as general-purpose bundlers across multiple JavaScript frameworks, though Trunk's scope is narrower and focused specifically on the WebAssembly compilation and bundling problem rather than general-purpose JavaScript bundling. In practice, Trunk is used as the default development and build tool for most Rust-to-WebAssembly frontend projects, regardless of which UI framework they use, because it removes the need to hand-maintain wasm-bindgen invocations, asset copying, and manual HTML injection during every build. Its configuration is typically minimal, often just the annotated index.html file plus an optional Trunk.toml configuration file for advanced settings like proxy setup for API calls made during local development. The trade-offs are mostly about scope: Trunk focuses narrowly on the compile-and-bundle problem and does not provide the broader plugin ecosystems, code-splitting sophistication, or hot-module-replacement granularity found in mature JavaScript bundlers like webpack or Vite. Rust's compile times also mean Trunk's rebuild-on-change cycle is generally slower than equivalent JavaScript tooling, a limitation inherited from the underlying Rust compiler rather than Trunk itself or its bundling logic.
Key Features
- Compiles Rust crates to WebAssembly and bundles the output automatically
- Serves projects locally with automatic rebuild on file changes
- Processes and bundles CSS and Sass alongside compiled WebAssembly
- Works with any Rust UI framework that targets WebAssembly
- Injects required script tags into HTML based on simple link annotations
- Produces optimized, deployable static output for production
- Supports development-time proxy configuration for backend API calls