# vite-plugin-wasm

> Add WebAssembly ESM integration (aka. Webpack's `asyncWebAssembly`) to Vite and support `wasm-pack` generated modules.

Latest version **3.6.0** (published 2026-03-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-wasm
pnpm add vite-plugin-wasm
yarn add vite-plugin-wasm
bun add vite-plugin-wasm
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.6.0 |
| Published | 2026-03-15 |
| First published | 2022-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 434 |
| Author | Menci |
| Maintainers | menci |
| Keywords | vite, plugin, wasm, webassembly, wasm-pack, es-modules, modules |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-wasm
- Repository: https://github.com/Menci/vite-plugin-wasm
- Homepage: https://github.com/Menci/vite-plugin-wasm#readme
- Issues: https://github.com/Menci/vite-plugin-wasm/issues
- npm.io page: https://npm.io/package/vite-plugin-wasm

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 3.6.0 (latest) — 2026-03-15
- 3.5.0 — 2025-07-09
- 3.4.1 — 2024-12-20
- 3.4.0 — 2024-12-19
- 3.3.0 — 2023-12-13
- 3.2.2 — 2023-03-07
- 3.2.1 — 2023-02-05
- 3.1.1 — 2023-01-03
- 3.1.0 — 2022-10-22
- 3.0.0 — 2022-09-22
- 2.1.0 — 2022-07-20
- 2.0.0 — 2022-07-19
- 1.0.1 — 2022-06-29
- 1.0.0 — 2022-05-27
- 0.0.2 — 2022-03-05
- … 1 more at https://npm.io/package/vite-plugin-wasm/versions

## README

# vite-plugin-wasm

[![Test Status](https://img.shields.io/github/actions/workflow/status/Menci/vite-plugin-wasm/test.yaml?branch=main&style=flat-square)](https://github.com/Menci/vite-plugin-wasm/actions?query=workflow%3ATest)
[![npm](https://img.shields.io/npm/v/vite-plugin-wasm?style=flat-square)](https://www.npmjs.com/package/vite-plugin-wasm)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![License](https://img.shields.io/github/license/Menci/vite-plugin-wasm?style=flat-square)](LICENSE)

Add WebAssembly ESM integration (aka. Webpack's `asyncWebAssembly`) to Vite and support `wasm-pack` generated modules.

## Installation

This plugin supports Vite 2.x to 8.x. Just install it:

```bash
yarn add -D vite-plugin-wasm
```

## Usage

You also need the `vite-plugin-top-level-await` plugin unless you target very modern browsers only (i.e. set `build.target` to `esnext`).

```typescript
import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";

export default defineConfig({
  plugins: [
    wasm(),
    topLevelAwait()
  ]
});
```

If you are getting ESBuild errors of WASM files (In the format `No loader is configured for ".wasm" files: node_modules/somepackage/somefile.wasm`) with **Vite < 3.0.3**, please upgrade your Vite to **>= 3.0.3 or upgrade this plugin to >= 3.1.0**. A workaround is adding the corresponding imported module within `node_modules` to `optimizeDeps.exclude`, e.g.:

```typescript
export default defineConfig({
  optimizeDeps: {
    exclude: [
      "@syntect/wasm"
    ]
  }
});
```

## Web Worker

To use this plugin in Web Workers. Add it (and `vite-plugin-top-level-await` if necessary) to `worker.plugins`. To support Firefox, don't use ES workers. leave `worker.format` default and use `vite-plugin-top-level-await` >= 1.4.0 (see also [here](https://github.com/Menci/vite-plugin-top-level-await#workers)):

```typescript
export default defineConfig({
  plugins: [
    wasm(),
    topLevelAwait()
  ],
  worker: {
    // Not needed with vite-plugin-top-level-await >= 1.3.0
    // format: "es",
    plugins: [
      wasm(),
      topLevelAwait()
    ]
  }
});
```

# Notes

TypeScript typing is broken. Since we can't declare a module with `Record<string, any>` as its named export map, your `import ... from "./module.wasm";` will still get Vite's built-in typing, but the transformed code is fine. Thus, you can simply use an asterisk import `import * as wasmModule from "./module.wasm"` and type assertion (you have typing for your WASM files, right?).

---
_Source: https://npm.io/package/vite-plugin-wasm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
