Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/grafbase/getting-started-with-rust-wasm

Rust ➡ WebAssembly for Webpack, Node.js and Deno
https://github.com/grafbase/getting-started-with-rust-wasm

blog deno educational-project javascript js nodejs rust rust-lang template ts typescript wasm wasm-bindgen wasm-pack webassembly webpack

Last synced: 3 months ago
JSON representation

Rust ➡ WebAssembly for Webpack, Node.js and Deno

Awesome Lists containing this project

README

        

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

- [Install Rust](https://www.rust-lang.org/learn/get-started)
- [Install Node.js](https://nodejs.org/)
- [Install `wasm-pack`](https://rustwasm.github.io/wasm-pack/installer/)
- Run `npm install`

## Node.js

- [Install Rust](https://www.rust-lang.org/learn/get-started)
- [Install Node.js](https://nodejs.org/)
- [Install `wasm-pack`](https://rustwasm.github.io/wasm-pack/installer/)
- Alternatively, [install `cargo-make`](https://github.com/sagiegurari/cargo-make#installation)

## Deno

- [Install Rust](https://www.rust-lang.org/learn/get-started)
- [Install Node.js](https://nodejs.org/)
- [Install `cargo-make`](https://github.com/sagiegurari/cargo-make#installation)

## With Nix

1. [Install Nix](https://nixos.org/download.html)
2. [Activate Flakes](https://nixos.wiki/wiki/Flakes)
3. [Install direnv](https://direnv.net/)
4. [Install nix-direnv](https://github.com/nix-community/nix-direnv)
5. Add the following `.envrc` file:

```sh
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](http://localhost:8080/)

## Deno

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