- Setup for the Rust WASM "Game of Life" demo
cargo install wasm-packcargo install cargo-generatenpmshould already be installed
- Cloning the "Game of Life" demo
cargo generate --git https://github.com/rustwasm/wasm-pack-template- You'll be prompted for the target output directory name
wasm-game-of-life; this will be called$WASM_GOLbelow
- You'll be prompted for the target output directory name
- Set up the wasm-bindgen workflow
cd $WASM_GOLwasm-pack init- This creates a directory called
${WASM_GOL}/pkg, with the correct JavaScript bits needed to interact with a Rust WASM application - The JavaScript bits will need to be regenerated via
wasm-pack initevery time you make changes to the Rust code
- This creates a directory called
- Create the web app from a template
cd $WASM_GOLnpm init wasm-app www
- Install dependencies
cd ${WASM_GOL}/wwwnpm install
- Create local (non-NPM links)
cd ${WASM_GOL}/pkgnpm link
- Create links to the local non-NPM packages
cd ${WASM_GOL}/wwwnpm link wasm-game-of-life
- Edit
${WASM_GOL}/www/index.js, and change the name of the package to usecd ${WASM_GOL}/wwwvim index.js- Do
s/hello-wasm-pack/wasm-game-of-life/in the lineimport * as wasm from "hello-wasm-pack"
- Start a dev web server in the application directory
cd ${WASM_GOL}/wwwnpm run start- The dev web server will pick an unused port on the local machine and start serving web pages via HTTP
- Look for the server URI in the log output when starting the dev web
server
- "Project is running at http://localhost:8081/"
- Make changes to the source as needed, then rerun the
wasm-packcommand againcd $WASM_GOLwasm-pack init
Created
September 13, 2018 22:31
-
-
Save spicyjack/e73a9cfd87d230fa09c7e08216452333 to your computer and use it in GitHub Desktop.
RustWASM setup steps
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment