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 🙏

© 2025 – Pkg Stats / Ryan Hefner

vite-plugin-wasm-module-workers

v0.0.2

Published

A Vite plugin to use WASM with Vite and Cloudflare

Downloads

135

Readme

vite-plugin-wasm-module-workers (VPWMW)

Handle bundling WASM modules like Satori (Yoga and Resvg WASM) files for both Vite and Cloudflare.

Used on code.charliegleason.com (GitHub repo).

Installation

npm i vite-plugin-wasm-module-workers -D

And then in your vite.config.ts:

import wasmModuleWorkers from 'vite-plugin-wasm-module-workers'

export default defineConfig({
  plugins: [
    wasmModuleWorkers(),
    // ... more plugins
  ],
})

You'll also need to make sure you copy the WASM files to where Cloudflare expects them, usually at the end of the build process.

For example, in your package.json:

{
  "scripts": {
    "build": "remix vite:build && cp -f build/client/assets/*.wasm build/server/assets"
  }
}

How does it work?

Let's say we're using Satori to generate an og:image in our Vite Remix app.

It's important to only import .wasm with ?url, which helps ensure Vite doesn't try to do anything fancy with it.

First, we import the dependencies:

import satori, { init as initSatori } from 'satori/wasm'
import { Resvg, initWasm as initResvg } from '@resvg/resvg-wasm'
import initYoga from 'yoga-wasm-web'

import YOGA_WASM from 'yoga-wasm-web/dist/yoga.wasm?url'
import RESVG_WASM from '@resvg/resvg-wasm/index_bg.wasm?url'

Then, in our default function:

export async function createOGImage(title: string, requestUrl: string) {
  const { default: resvgwasm } = await import(
    /* @vite-ignore */ `${RESVG_WASM}?module`
  )
  const { default: yogawasm } = await import(
    /* @vite-ignore */ `${YOGA_WASM}?module`
  )

  try {
    if (!initialised) {
      await initResvg(resvgwasm)
      await initSatori(await initYoga(yogawasm))
      initialised = true
    }
  } catch (e) {
    initialised = true
  }

  // more fancy code

To trigger the plugin on a file, you'll need to have ?module in there. For example:

import RESVG_WASM from '@resvg/resvg-wasm/index_bg.wasm?url'

const { default: resvgwasm } = await import(
  /* @vite-ignore */ `${RESVG_WASM}?module`
)

Once running, the main things the plugin will look out for are:

  • The constant in import RESVG_WASM from 'yoga-wasm-web/dist/yoga.wasm?url'
  • The variable name in const { default: resvgwasm } ...
  • The constant in ${RESVG_WASM}

[!WARNING] My ability to write regualar expresions is not one of my strengths, so if things aren't working I'd recommend trying to match the imports and const { default: whateverWarmModule } = await import... to what it is in the example above. If you have a better handle on regex and are keen to improve it, check out contributing. I'm not confident how nicely this set up will play with different types of WASM imports, so here be dragons.

VPWMW will take this code on build and convert it to something Cloudflare expects:

)
import YOGA_WASM from './assets/yoga-CP4IUfLV.wasm'
import RESVG_WASM from './assets/index_bg-Blvrv-U2.wasm'
let initialised = false

async function createOGImage(title, requestUrl) {
  const resvgwasm = RESVG_WASM
  const yogawasm = YOGA_WASM
  try {
    if (!initialised) {
      await initWasm(resvgwasm)
      await init(await initYoga(yogawasm))
      initialised = true
    }
  } catch (e) {
    initialised = true
  }

  // more fancy build code

Magic. ✨

Contributing

This plugin also contains some pretty rough regular expressions to convert the code, so if you have any better suggestions for how that could work, I encourage you to open an issue or, even better, a PR.