Example of integrating WASM & web workers with a Typescript NextJS project.
yarn
yarn dev
- Open
localhost:3000
- Rust code is in
./rust
, generated withwasm-pack new
and built as a part of the Next build withwasm-pack-plugin
. - Workers are in
./src
. Types for worker module are intypings.d.ts
. - wasm is imported in
wasm.worker.ts
using the Webpack 4/5syncWebAssembly
method. - Workers are imported in
./pages/index.tsx
using Webpack 5's built-in Worker support. next.config.js
orchestrates the necessary Webpack 5 settings,wasm-pack-plugin
, and patches NextJS to allow wasm in workers.