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

vite-plugin-wasm-module

v0.0.0

Published

Vite plugin that loads each .wasm import as a WebAssembly.Module, like Convex and Cloudflare Workers

Readme

vite-plugin-wasm-module

A Vite plugin that loads each .wasm import as a WebAssembly.Module. Use it to run code for Convex or Cloudflare Workers in Vitest or in the Vite dev server.

How a .wasm import loads

import wasmModule from "./module.wasm";

wasmModule instanceof WebAssembly.Module; // true

const instance = await WebAssembly.instantiate(wasmModule, {
  wbg: {/* the imports of the module */},
});

The default export is a compiled module. The plugin does not instantiate it and does not resolve its imports. Your code instantiates the module and gives the imports.

The Convex runtime and Cloudflare Workers load a .wasm import the same way. Thus, code that runs in these runtimes also runs in Vite with this plugin, without changes.

This is the same as the web target of wasm-bindgen, which gives its imports when it instantiates the module:

import init from "./pkg/my_crate.js";
import wasmModule from "./pkg/my_crate_bg.wasm";

await init({ module_or_path: wasmModule });

Other ways to load .wasm files

| Import | Gives | Where | | -------------------------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | | import m from "x.wasm" | A WebAssembly.Module | This plugin, Convex, Cloudflare Workers | | import * as m from "x.wasm" | The exports of an instance, with imports resolved as ES modules | vite-plugin-wasm, webpack asyncWebAssembly | | import init from "x.wasm?init" | A function that instantiates the module | Vite |

The second row follows the WebAssembly ES module integration proposal. It resolves each import of the module as a package. Thus it fails with the output of the web target of wasm-bindgen, whose imports (for example wbg) are not packages.

The plugin does not change an import with a query, such as x.wasm?init or x.wasm?url. Vite handles these imports.

Installation

npm install --save-dev vite-plugin-wasm-module

Usage with Vitest

import { defineConfig } from "vitest/config";
import wasmModule from "vite-plugin-wasm-module";

export default defineConfig({
  plugins: [wasmModule()],
  test: {
    server: {
      deps: {
        // The packages that import `.wasm` files.
        inline: ["my-wasm-package"],
      },
    },
  },
});

Vitest gives the files of most dependencies directly to Node, and Vite plugins do not see their imports. If a dependency imports a .wasm file, add the dependency to test.server.deps.inline. Then Vitest sends its imports through the plugins.

Usage with the Vite dev server

import { defineConfig } from "vite";
import wasmModule from "vite-plugin-wasm-module";

export default defineConfig({
  plugins: [wasmModule()],
});

The plugin applies only when Vite serves the code: in the dev server and in Vitest. It does not change vite build. It inlines the bytes of each .wasm file as base64 in the JavaScript, which is good for tests but makes a large bundle.

TypeScript

Add a reference to the type of .wasm imports in a declaration file of your project, for example src/env.d.ts:

/// <reference types="vite-plugin-wasm-module/client" />

Or add it to compilerOptions.types of your tsconfig.json. This list replaces the types that TypeScript includes automatically, thus keep the entries that you already have:

{
  "compilerOptions": {
    "types": ["node", "vite/client", "vite-plugin-wasm-module/client"]
  }
}

Or add a declaration file:

declare module "*.wasm" {
  const module: WebAssembly.Module;
  export default module;
}