rsbuild-plugin-wasmpack
is a plugin for rsbuild that enables you to compile and build Rust crates into WebAssembly (Wasm) using wasm-pack.
This plugin simplifies the integration of Rust to WebAssembly in your rsbuild projects, allowing you to easily compile and bundle your Rust code for use in web applications.
Before using the plugin, make sure you have:
You can add rsbuild-plugin-wasmpack
as a development dependency using your preferred package manager:
npm install --save-dev rsbuild-plugin-wasmpack
bun add -d rsbuild-plugin-wasmpack
pnpm add -D rsbuild-plugin-wasmpack
yarn add -D rsbuild-plugin-wasmpack
Once installed, you can add the plugin to your rsbuild
configuration. Here’s an example configuration for compiling a Rust crate to WebAssembly:
import { defineConfig } from "@rsbuild/core";
import { pluginWasmPack } from "rsbuild-plugin-wasmpack";
export default defineConfig({
plugins: [
pluginWasmPack({
crates: [
{
path: "rust1", // The path to your Rust crate
output: "wasm1", // The output directory for your wasm package
target: "web", // The target environment (e.g., 'web', 'nodejs')
},
{
path: "rust2",
output: "wasm2",
target: "web",
},
],
}),
],
});
-
path
(string): The path to your Rust crate or project. This is typically the folder containingCargo.toml
. -
output
(string): The directory where the generated.wasm
package will be placed. -
target
(string): The WebAssembly target. See all supported targets in the wasm-pack documentation.