← 返回命令列表

Linux command

trunk 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Build the project

trunk build

Build for release

trunk build --release

Serve with hot reload

trunk serve

Serve on a specific port and address

trunk serve --port [3000] --address [0.0.0.0]

Serve with a backend proxy

trunk serve --proxy-backend=http://localhost:[9000]/api/

Watch for changes and rebuild

trunk watch

Clean build artifacts

trunk clean

说明

Trunk is a build tool for Rust WebAssembly applications that handles compilation, bundling, and serving. It compiles Rust code to WebAssembly, processes assets like CSS and JavaScript, and generates the HTML and JavaScript glue code needed to run WASM modules in the browser. The development server provides hot reloading, automatically rebuilding and refreshing the browser when source files change. Release builds apply optimizations including WASM size reduction for production deployment. Trunk integrates with wasm-bindgen for JavaScript interop and works with frameworks like Yew, Leptos, and Seed. Configuration is managed through a Trunk.toml file in the project root.

参数

build
Build the project, compiling Rust to WASM and bundling assets.
serve
Start development server with hot reloading.
watch
Watch for file changes and rebuild automatically.
clean
Remove build artifacts (dist directory).
--release
Enable release optimizations including WASM size reduction.
--public-url _URL_
Public URL prefix for asset paths.
--port _PORT_
Port for the dev server (default: 8080).
--address _ADDR_
Address to bind the dev server to.
--proxy-backend _URL_
Proxy requests to a backend server. The URI path of the URL determines the proxy path.
--proxy-rewrite _URI_
Alternative URI on which to listen for proxy requests.

FAQ

What is the trunk command used for?

Trunk is a build tool for Rust WebAssembly applications that handles compilation, bundling, and serving. It compiles Rust code to WebAssembly, processes assets like CSS and JavaScript, and generates the HTML and JavaScript glue code needed to run WASM modules in the browser. The development server provides hot reloading, automatically rebuilding and refreshing the browser when source files change. Release builds apply optimizations including WASM size reduction for production deployment. Trunk integrates with wasm-bindgen for JavaScript interop and works with frameworks like Yew, Leptos, and Seed. Configuration is managed through a Trunk.toml file in the project root.

How do I run a basic trunk example?

Run `trunk build` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does build do in trunk?

Build the project, compiling Rust to WASM and bundling assets.