vite-plugin-wasm-rust
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

vite-plugin-wasm-rust

A lightweight wrapper for wasm-pack, designed to enhance the experience of building websites in rust.

Features

  • Supports Cargo workspaces
  • Monitors files and directories for changes
  • Rebuilds and reloads browser page upon file modifications
  • Displays compilation errors directly in the browser
  • Small, easy to read and modify

Getting Started

Add vite.config.js to build and watch rust files in src dir

import { defineConfig } from "vite";
import viteWasmPack from "vite-plugin-wasm-rust";

export default defineConfig(({ mode }) => {
  const release = mode != "development";
  return {
    root: ".",
    build: {
      target: "esnext",
    },
    server: {
      hmr: { overlay: true },
    },
    plugins: [
      viteWasmPack({
        build: {
          crate: "./",
          release: release,
          enable_opt: release,
        },
        watch: {
          include: ["./src/", "./styles"],
          exclude: ["./dist/**"],
        },
      }),
    ],
  };
});

add scripts to package.json

{
  "scripts": {
    "dev": "vite -c vite.config.js",
    "build": "vite build -c vite.config.js"
  }
}

then run dev mode

npm run dev

License

MIT or Apache 2.0

Dependents (0)

Package Sidebar

Install

npm i vite-plugin-wasm-rust

Weekly Downloads

15

Version

1.0.2

License

(MIT OR Apache-2.0)

Unpacked Size

5.16 kB

Total Files

4

Last publish

Collaborators

  • alfatm