rsnext/examples/with-webassembly
2022-12-15 10:08:03 +01:00
..
components Fix with-webassembly example and convert to Typescript (#43677) 2022-12-11 20:10:14 -06:00
pages feat: enables 'edge' as a possible runtime for API routes (#44045) 2022-12-15 10:08:03 +01:00
src Add WebAssembly example 2018-09-17 21:48:06 +02:00
.gitignore Update default gitignore templates (#39051) 2022-07-26 20:08:40 -05:00
add.wasm Add WebAssembly example 2018-09-17 21:48:06 +02:00
next.config.js Fix with-webassembly example and convert to Typescript (#43677) 2022-12-11 20:10:14 -06:00
package.json Fix with-webassembly example and convert to Typescript (#43677) 2022-12-11 20:10:14 -06:00
README.md Fix with-webassembly example and convert to Typescript (#43677) 2022-12-11 20:10:14 -06:00
tsconfig.json Fix with-webassembly example and convert to Typescript (#43677) 2022-12-11 20:10:14 -06:00
wasm.d.ts Fix with-webassembly example and convert to Typescript (#43677) 2022-12-11 20:10:14 -06:00

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.

Preview

Preview the example live on StackBlitz:

Open in StackBlitz

How to use

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

npx create-next-app --example with-webassembly with-webassembly-app
yarn create next-app --example with-webassembly with-webassembly-app
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:

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