vite-plugin-workers-rs-unofficial

raw JSON →
0.3.0 verified Fri May 01 auth: no javascript

An unofficial community-maintained Vite plugin (v0.3.0) that integrates Rust worker-build with @cloudflare/vite-plugin, enabling development and deployment of Cloudflare Workers written in Rust using Vite's dev server, HMR, and build pipeline. Key differentiators: it automatically compiles Rust to WebAssembly via worker-build, handles file watching with debounce, and configures @cloudflare/vite-plugin for seamless dev and build workflows. Requires Rust toolchain, wasm32-unknown-unknown target, and worker-build CLI. Release cadence is rapid, with multiple minor versions per months.

error Error: Cannot find module 'vite-plugin-workers-rs-unofficial'
cause Package not installed or missing from node_modules.
fix
Run npm install -D vite-plugin-workers-rs-unofficial or ensure it is in package.json devDependencies.
error TypeError: (0 , vite_plugin_workers_rs_unofficial.cloudflareRustWorker) is not a function
cause Using CommonJS `require` instead of ESM import.
fix
Change const { cloudflareRustWorker } = require(...) to import { cloudflareRustWorker } from 'vite-plugin-workers-rs-unofficial'.
error Error: worker-build not found. Install with `cargo install worker-build`
cause The `worker-build` CLI is not installed or not in PATH.
fix
Install worker-build: cargo install worker-build and ensure it is on your PATH.
gotcha The `outDir` option in `rustBuild` must match the directory specified in `wrangler.jsonc` `main` field.
fix Ensure `rustBuild.outDir` (default 'build') matches wrangler.jsonc's `main` directory.
gotcha The plugin is unofficial and not affiliated with Cloudflare. No official support or guarantees.
fix Review the plugin source and verify compatibility with your Cloudflare Workers setup.
gotcha During development, the plugin restarts the Vite dev server after each successful rebuild, which may cause brief interruptions.
fix Adjust `debounceMs` and `maxRetries` options to reduce unnecessary restarts.
npm install vite-plugin-workers-rs-unofficial
yarn add vite-plugin-workers-rs-unofficial
pnpm add vite-plugin-workers-rs-unofficial

This config sets up the Rust worker plugin with Vite, specifying the worker environment and build output directory.

// vite.config.ts
import { defineConfig } from 'vite';
import { cloudflareRustWorker } from 'vite-plugin-workers-rs-unofficial';

export default defineConfig({
  plugins: [cloudflareRustWorker()],
  environments: {
    worker: {
      consumer: 'server',
      build: { outDir: 'dist/worker', emptyOutDir: false },
    },
  },
});