npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@waynevanson/vite-plugin-cargo

v4.0.0

Published

Import wasm_bingen compatible Rust to JavaScript via Vite

Readme

vite-plugin-cargo

A Vite plugin that seamlessly integrates Rust crates into your frontend project by compiling them to WebAssembly via cargo and wasm-bindgen.

Features

  • Zero-Config Compiling: Automatically detects the closest Cargo.toml.
  • Watch mode: Watches dependencies related to the entrypoint.
  • WASM-Bindgen Integration: Generates the necessary JS glue code automatically.
  • TypeScript Support: Automatically generates and syncs .d.ts files for your Rust exports.
  • HMR Support: Works with Vite's dev server.
  • Release Optimization: Automatically uses --release builds during vite build.

Prerequisites

You must have the following installed on your system:

  1. Rust and Cargo
  2. wasm32-unknown-unknown target: rustup target add wasm32-unknown-unknown
  3. wasm-bindgen-cli: cargo install -f wasm-bindgen-cli

Installation

npm install @waynevanson/vite-plugin-cargo --save-dev

Usage

1. Configure Vite

Add the plugin to your vite.config.ts. You must specify which files should be treated as Rust entrypoints using a glob pattern.

import { defineConfig } from "vite";
import { cargo } from "vite-plugin-cargo";

export default defineConfig({
  plugins: [
    cargo({
      // Files to treat as Cargo entrypoints
      includes: ["**/src/lib.rs"],
    }),
  ],
});

2. Prepare your Rust code

Ensure your Rust crate is configured as a cdylib.

Cargo.toml

[package]
name = "my-rust-lib"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2"

src/lib.rs

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn greet(name: &str) -> String {
    format!("Hello, {}!", name)
}

3. Import in JS/TS

import { greet } from "./src/lib.rs";

console.log(greet("Vite"));

Configuration Options

Base Configuration

| Option | Type | Description | | :-------------------- | :--------------------------------------- | :----------------------------------------------- | | includes | string \| string[] | Glob patterns of possible entry points. | | browserOnly | boolean | (Optional) Passes --browser to wasm-bindgen. | | noTypescript | boolean | (Optional) Disables .d.ts generation. | | cargoBuildOverrides | (args: Array<string>) => Array<string> | (Optional) Override args to cargo build. |

Rust Features

Additionally, one of the following configurations can be used with the base.

| Option | Type | Description | | :------------------ | :--------- | :------------------------------------------- | | features | string[] | (Optional) List of Cargo features to enable. | | noDefaultFeatures | boolean | (Optional) Disable default Cargo features. |

| Option | Type | Description | | :------------ | :-------- | :------------------------------------ | | allFeatures | boolean | (Optional) Enable all Cargo features. |


How it works

Transformation pipeline:

`.rs` -> `.wasm` + `.js` + `.d.ts`
  1. Detection: The plugin matches files via the includes glob.
  2. Metadata: It runs cargo metadata to find the correct cdylib target.
  3. Compilation: Runs cargo build --target wasm32-unknown-unknown.
  4. Binding: Runs wasm-bindgen on the resulting .wasm file to a local cache in node_modules/.cache.
  5. Resolution: Injects the generated JavaScript glue code into your Vite bundle.