• Stars
    star
    134
  • Rank 264,943 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 2 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

vite-plugin-wasm

Test Status npm Commitizen friendly code style: prettier License

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

Installation

Now this plugin supports both Vite 2.x and 3.x. Just install it:

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).

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.:

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.3.0:

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 got Vite's bulit-in typing, but the transformed code is fine. So just use an asterisk import import * as wasmModule from "./module.wasm" and type assertion (you have typing for your WASM files, right?).

More Repositories

1

vite-plugin-top-level-await

Transform code to support top-level await in normal browsers for Vite.
TypeScript
117
star
2

electron-titlebar

Cool titlebar for electron apps for every system
JavaScript
115
star
3

simple-sandbox

A simple Linux sandbox with Node.js API.
C++
69
star
4

acme

Issue free SSL certs on GitHub Actions with acme.sh.
35
star
5

oi.men.ci

Menci 的 OI 博客(源代码与网站文件)
JavaScript
27
star
6

monaco-tree-sitter

Highlight your Monaco Editor with tree-sitter grammar.
TypeScript
26
star
7

hexo-deployer-upyun

UPYUN deployer for Hexo.
JavaScript
22
star
8

html-parser

The task of Advanced Programming class on 2019/03/28. C++ HTML parser that generates a simple DOM tree.
C++
18
star
9

docker-archlinuxarm

Docker image for Arch Linux (multiarch ARM64 + AMD64, daily updated with GitHub Actions)
Dockerfile
18
star
10

docker-sandbox

Run unsafe program in docker sandbox
C++
18
star
11

homebrew-libvirt-m1

Homebrew formulaes to install `virt-manager`, `virt-viewer` and `libvirtd` on macOS with Apple Silicon
Ruby
16
star
12

magpie

Bidirectional NDP proxy and route maintainer to relay an IPv6 SLAAC network.
C++
16
star
13

wastyle

AStyle code formatter compiled to WebAssembly, for Node.js and the browser.
C++
16
star
14

resume

个人简历
14
star
15

markdown-it-merge-cells

A markdown-it plugin to merge adjacent cells with same content in tables
JavaScript
13
star
16

deploy-certificate-to-aliyun

GitHub Action to Deploy SSL certificate to Aliyun Certificates Service (and use in CDN).
JavaScript
10
star
17

service-worker-redirect-origin

Redirect requests of current origin to another domain with Service Worker.
TypeScript
10
star
18

vite-plugin-public-path

Vite's equivalent of `__webpack_public_path__` in Webpack. Works for `index.html` and modern/legacy build.
TypeScript
9
star
19

search-engine-oop

The task of Advanced Programming class on 2019/04/23. Text search engine using inversed index and TF-IDF in C++.
C++
8
star
20

stego

数据隐写:将数据嵌入到到 BMP 数据中
C
8
star
21

tree-sitter-wasm-prebuilt

Prebuilt WASM binaries for tree-sitter's language parsers.
JavaScript
8
star
22

double

The task of Advanced Programming class on 2018/10/10. Implementation of IEEE 754 floating point number. Like `double` in C.
C
8
star
23

chroot-sandbox

Run unsafe program in chroot sandbox
C++
8
star
24

aur.men.ci

Menci's prebuilt AUR repo for Archlinux and Manjaro
TypeScript
8
star
25

bootloader

操作系统课作业:MBR 引导加载器
Assembly
8
star
26

pipeline

Pipelined MIPS processor in Verilog
SystemVerilog
7
star
27

TuringAdvancedProgramming19A

Code of tasks of Turing Class 2019's Advanced Programming (first term)
C
7
star
28

hexo-renderer-syzoj-renderer

Render Hexo's markdown documents with syzoj-renderer
JavaScript
6
star
29

Menci

My GitHub homepage
6
star
30

SummerProgrammingPractice2020

"Summer Programming Practice 2020" for RUC Turing Class 2019
HTML
6
star
31

Blog

My new blog
TypeScript
6
star
32

moemark-turndown

Convert hexo-renderer-moemark-pygments rendered HTML back to markdown
JavaScript
6
star
33

search-engine

The task of Advanced Programming class on 2019/04/16. Text search engine using inversed index and TF-IDF.
Python
6
star
34

avl-tree

The task of Advanced Programming class on 2018/12/05. Implementation of AVL tree and heap memory leak check in C.
C
5
star
35

FakeTPM.kext

Something you might need to run Windows 11 🤣
5
star
36

deploy-certificate-to-upyun

GitHub Action to Deploy SSL certificate to Upyun CDN or OSS.
TypeScript
5
star
37

build-archlinux-package

GitHub Action to build Archlinux / Manjaro package with Docker, for AMD64 or ARM64
Shell
5
star
38

mepage-2015-archive

很久很久以前(2015 年)设计的个人主页 MePage 的存档
JavaScript
5
star
39

upload-to-oss

GitHub Actions to sync files in a directory to Aliyun OSS with a prefix incrementally, with filename filter.
TypeScript
5
star
40

web-crawler

The task of Advanced Programming class on 2019/03/21. C++ web crawler with wget.
C++
4
star
41

xinu-vm

操作系统课作业 xinu
C
4
star
42

pipeline-tester

Random tests generator & runner for your pipelined MIPS processor (from @t123yh)
C#
4
star
43

avl-tree-zip

The task of Advanced Programming class on 2018/12/26. Compress and decompress an avl-tree with (1 `double` + 1 `char`) for each node, or its insert sequence.
C
3
star
44

men.ci-backup

Menci's personal homepage
3
star
45

syntect-js

Syntect (Syntax highlighter in Rust) for Node.js and WebAssembly
JavaScript
3
star
46

FlappyBird

JavaScript
3
star
47

deploy-certificate-to-azure-web-app

GitHub Action to deploy SSL certificate to Azure Web App (including Function App)
2
star
48

luogu-openapi

Luogu OpenAPI SDK (unofficial)
TypeScript
2
star
49

tkpl

The "Ka" Programming Language
2
star
50

karatsuba-algorithm

The fast big integer multiplication algorithm
C++
2
star
51

big-integer

The task of Advanced Programming class on 2019/04/04. C++ BigInteger class.
C++
2
star
52

ssh-certdeploy

Deploy certificate to servers with SSH.
Shell
2
star
53

arcaea-builder

Build your own Arcaea game client to play self-made or modified official charts!
TypeScript
2
star
54

qsort

The task of Advanced Programming class on 2018/10/10. Implementation of C library function qsort().
C
2
star
55

CompilationPrinciples

编译原理作业:基于 flex 和 bison 的 Pascal 到 Intel x86_64 Assembly 编译器
C++
1
star
56

tpm2-luks-helper

Shell
1
star
57

.dotfiles

My ~/.dotfiles on GNU/Linux and macOS
1
star
58

sf-mono-webfont

SF Mono webfont (WOFF & WOFF2) generated with FontSquirrel.
HTML
1
star
59

mdb

Menci DeBugger: Simple Linux x86_64 debugger with ptrace(2)
C++
1
star
60

ics2

RUC ICS2 Labs
C
1
star
61

docker-polyfill-service

Dockerized polyfill-service (https://github.com/Financial-Times/polyfill-service, aka. https://polyfill.io)
Dockerfile
1
star