Skip to content

WebAssembly Module Starter Code, Powered by Rust, wasm-pack, wasm-bindgen and Webpack πŸ”₯😍

Notifications You must be signed in to change notification settings

adamisntdead/wasm-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WebAssembly Starter

WebAssembly Module Starter Code, Powered by Rust, wasm-pack, wasm-bindgen and Webpack πŸ”₯ 😍

If you want an explanation of all of the code in this (rather minimal) boilerplate, check out the Explanation

Setup

First you are gonna have to get Rust at rust-lang.org. Then, you will need to have nodejs installed.

For the WebAssembly side of things, you are going to have to get to Rust nightly, and install the WebAssembly compiler.

rustup default nightly
rustup target add wasm32-unknown-unknown --toolchain nightly

Then, you are going to need wasm-pack

cargo install wasm-pack

Finally, you can compile the WebAssembly module.

# Run wasm-pack
wasm-pack init .

# Install the example files
cd example
npm install
npm run serve

Note: It can take about 3 minutes just to do that initial wasm-pack so be ready! You can then open the page at localhost:8080

Usage

The file wasm_starter.js exposes a single method hello_world(), which just displays a hello world input

If you setup Webpack 4, it supports webassembly out of the box, and the module can be used like so:

const js = import('../pkg/wasm_starter.js')

js.then(js => {
  js.hello_world()
})

Which displays:

Hello World!

License

MIT

About

WebAssembly Module Starter Code, Powered by Rust, wasm-pack, wasm-bindgen and Webpack πŸ”₯😍

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published