Back to Next Js

WebAssembly example

examples/with-webassembly/README.md

16.2.51.3 KB
Original Source

WebAssembly example

This example shows how to import WebAssembly files (.wasm) and use them inside of a React component that is server rendered. So the WebAssembly code is executed on the server too. In the case of this example we're showing Rust compiled to WebAssembly.

Deploy your own

How to use

Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:

bash
npx create-next-app --example with-webassembly with-webassembly-app
bash
yarn create next-app --example with-webassembly with-webassembly-app
bash
pnpm create next-app --example with-webassembly with-webassembly-app

This example uses Rust compiled to wasm, the wasm file is included in the example, but to compile your own Rust code you'll have to install Rust.

To compile src/add.rs to add.wasm run:

bash
npm run build-rust
# or
yarn build-rust
# or
pnpm build-rust