- Notifications
You must be signed in to change notification settings - Fork1
A Wasm/TS/ESM in Node/Jest/Next.js demo
License
hasharchives/wasm-ts-esm-in-node-jest-and-nextjs
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This repo contains a web app that depends on an NPM package withWasm, TypeScript and native ESModules.Wasm code is successfully used in a Node.js script, a Jest test and a Next.js app within a page and an API route.
The demo was created while working onblockprotocol/blockprotocol andhashintel/hash.
Clone the repo and install dependencies from the root folder:
yarn install
(can be skipped) Generate
wasm-packagefromwasm-crate:cd wasm-cratewasm-pack build --out-dir ../wasm-package --target=bundlercd ..
(can be skipped) Tweak
wasm-package:## Enable native ESM in package.jsonyarn replace-in-file"/\"module\":/""\"type\":\"module\",\"main\":" wasm-package/package.json --isRegexyarn prettier --write wasm-package/package.json## Remove autogenerated .gitignorerm wasm-package/.gitignore
This step won’t be necessary whenrustwasm/wasm-pack#1061 is merged and released.
🎉 Run a Node.js script that uses the
wasm-package:yarn workspace web-app exe scripts/wasm-package-answer.ts
🎉 Run unit tests referring to the
wasm-package:yarn workspace web-apptestNeeds Jest
>=29.3.0, seefacebook/jest#13505.🎉 Run Next.js dev server and check if
wasm-packageworks there too:yarn workspace web-app dev
Openlocalhost:3000 andlocalhost:3000/api/wasm-package-answer to see the result.
⚠️ Note theworkaround inweb-app/next.config.js.🎉 Build and run production Next.js app:
yarn workspace web-app buildyarn workspace web-app start
About
A Wasm/TS/ESM in Node/Jest/Next.js demo
Resources
License
Uh oh!
There was an error while loading.Please reload this page.