#run-wasm #dev-tools #web

app wasm-server-runner

cargo run for wasm programs

13 unstable releases (5 breaking)

0.6.3 Feb 7, 2024
0.6.1 Nov 30, 2023
0.5.1 Nov 21, 2023
0.4.0 Oct 27, 2022
0.1.0 Dec 10, 2021

#221 in WebAssembly

Download history 87/week @ 2023-12-21 120/week @ 2023-12-28 139/week @ 2024-01-04 133/week @ 2024-01-11 115/week @ 2024-01-18 116/week @ 2024-01-25 124/week @ 2024-02-01 113/week @ 2024-02-08 107/week @ 2024-02-15 114/week @ 2024-02-22 161/week @ 2024-02-29 105/week @ 2024-03-07 71/week @ 2024-03-14 80/week @ 2024-03-21 123/week @ 2024-03-28 69/week @ 2024-04-04

364 downloads per month
Used in bevy_spatial

MIT license

24KB
370 lines

wasm-server-runner

Allows you to run programs in the browser using web assembly using a simple cargo run.

Usage

Step 1.

rustup target add wasm32-unknown-unknown
cargo install wasm-server-runner

Step 2.

Add this to your ~/.cargo/config.toml (not the Cargo.toml of your project!):

[target.wasm32-unknown-unknown]
runner = "wasm-server-runner"

Step 3.

Run programs in the browser using

cargo run --target wasm32-unknown-unknown
cargo run --target wasm32-unknown-unknown --example example

wasm-server-runner path/to/file.wasm

Example output:

INFO wasm_server_runner: wasm output is 49.79kb large
INFO wasm_server_runner: starting webserver at http://127.0.0.1:1334

The website will reload when the server is restarted and serve files relative to the current directory.

Configuration options

All configuration options can be specified via environment variables.

WASM_SERVER_RUNNER_ADDRESS

Default: 127.0.0.1 Control the address that the server listens on. Set to 0.0.0.0 to allow access from anywhere.

WASM_SERVER_RUNNER_DIRECTORY

Default: .

Can be used to specify where relative path requests are loaded from.

WASM_SERVER_RUNNER_CUSTOM_INDEX_HTML

Default: none

When set, will try to load the custom index.html from that path instead of the default. Can be relative to the directory.

Note: To support both module and non-module style the index.html needs to have specific string that will be replaced at runtime. The body should contain something like

{{ NO_MODULE }}
<script type="module">
    // {{ MODULE }}
</script>
WASM_SERVER_RUNNER_HTTPS

Default: false

Controls whether https is used.

WASM_SERVER_RUNNER_NO_MODULE

Default: false

Controls whether the wasm-bindgen output uses modules or not.

Dependencies

~29–45MB
~804K SLoC