Skip to content

grafbase/getting-started-with-rust-wasm

Repository files navigation

Getting Started With Rust and WebAssembly

A design with Rust's Ferris and the WebAssembly logo

Rust ➡ WebAssembly for Webpack, Node.js and Deno
See Getting started with Rust and WebAssembly

Try It Out

CodeSandbox: getting-started-with-rust-wasm

Setup

Webpack

Node.js

Deno

With Nix

  1. Install Nix

  2. Activate Flakes

  3. Install direnv

  4. Install nix-direnv

  5. Add the following .envrc file:

    use flake  # activates the flake
    dotenv_if_exists .env  # optionally loads a .env file if it exists
  6. Run direnv allow . inside the project directory to allow Direnv to execute the .envrc

  7. For Webpack, also run npm install

Usage

Node.js

With wasm-pack

  1. wasm-pack build --target nodejs - Builds and generates bindings for src/lib.rs
  2. node src/node.mjs - Runs src/node.mjs

With cargo-make

  • cargo make run-node - Runs src/node.mjs

Webpack

  1. npm run serve
  2. Open http://localhost:8080

Deno

  • cargo make run-deno - Runs src/deno.ts