Skip to content

Files

Latest commit

feb4441 · Jul 24, 2023

History

History

with-webassembly

WebAssembly example

This example shows how to import WebAssembly files (.wasm) and use them inside of a Nullstack component in both server and client environments. In the case of this example we're showing Rust and Go compiled to WebAssembly.

Deploy your own

Deploy it now with Vercel or preview on StackBlitz:

Deploy with Vercel Open in StackBlitz

How to use

Execute nulla create with npm:

npx nulla create --example with-webassembly with-webassembly-app

Then deploy it with Vercel, Heroku or Netlify.

Compiling to WASM

Rust

The WASM file is included in the example, but to compile your own Rust code you'll have to install Rust.

To compile src/rust/src/main.rs to src/rust/main.wasm run:

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

Go

The WASM file is included in the example, but to compile your own Go code you'll have to install both Go and TinyGo (used to generate optimized Go binaries).

To compile src/go/src/main.rs to src/go/main.wasm run:

npm run build:go
# or
yarn build:go
# or
pnpm build:go