A Vite plugin which recompiles your Rust WebAssembly project whenever you modify a Rust (*.rs) file.
- Add it to your
vite.config.(js|ts)
file and set thebuild.watch
parameter to listen for .rs file changes as well:
import { defineConfig } from "vite";
import wasmPackWatchPlugin from "vite-plugin-wasm-pack-watcher";
export default defineConfig({
build: {
watch: {
include: ["src/**/*.js", "src/**/*.ts", "src/**/*.rs"], // Watch for *.rs files
},
},
plugins: [
wasmPackWatchPlugin({
/*
buildCommand: "<your custom build command to run, defaults to wasm-pack build --dev>"
*/
}),
],
});
Note: Please note that this plugin is not a replacement for vite-plugin-wasm or similar plugins!
- If you're importing the WASM package generated by
wasm-pack
in your package.json you need to reference it as a "link", otherwise this plugin will keep reloading the old, unchanged version!
{
"dependencies": {
"<your wasm package name>": "link:./pkg"
}
}