Skip to content

A Vite plugin which recompiles your Rust WebAssembly project whenever you modify a Rust (*.rs) file.

License

Notifications You must be signed in to change notification settings

mtolmacs/vite-plugin-wasm-pack-watcher

Repository files navigation

vite-plugin-wasm-pack-watcher

A Vite plugin which recompiles your Rust WebAssembly project whenever you modify a Rust (*.rs) file.

Usage

  1. Add it to your vite.config.(js|ts) file and set the build.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!

  1. 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"
  }
}

About

A Vite plugin which recompiles your Rust WebAssembly project whenever you modify a Rust (*.rs) file.

Resources

License

Stars

Watchers

Forks

Packages

No packages published