rashtell / next-wasm-workers

Example repo for getting NextJS, Rust via wasm-pack, and web workers all playing nicely together.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example of integrating WASM & web workers with a Typescript NextJS project.

Running

  1. yarn
  2. yarn dev
  3. Open localhost:3000

Layout

  • Rust code is in ./rust, generated with wasm-pack new and built as a part of the Next build with wasm-pack-plugin.
  • Workers are in ./src. Types for worker module are in typings.d.ts.
  • wasm is imported in wasm.worker.ts using the Webpack 4/5 syncWebAssembly 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.

About

Example repo for getting NextJS, Rust via wasm-pack, and web workers all playing nicely together.


Languages

Language:JavaScript 31.2%Language:TypeScript 30.6%Language:CSS 24.8%Language:Rust 13.4%