Skip to content

Instantly share code, notes, and snippets.

@live-wire
Last active October 4, 2022 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save live-wire/c172f14e73f8b06192764b389ba28ce5 to your computer and use it in GitHub Desktop.
Save live-wire/c172f14e73f8b06192764b389ba28ce5 to your computer and use it in GitHub Desktop.
Compiling Bevy game to WASM on x86-intel Mac

Instructions


  • rustup target install wasm32-unknown-unknown

  • cargo install wasm-server-runner

  • cargo install wasm-bindgen-cli

  • Add this to your Cargo.toml

[target.wasm32-unknown-unknown]
runner = "wasm-server-runner"
  • cargo build --release --target wasm32-unknown-unknown
  • wasm-bindgen --out-dir ./out/ --target web ./target/wasm32-unknown-unknown/release/your_awesome_game.wasm
  • Add your assets to this output folder. (out/)
  • Create an index.html in this output folder that includes the generated js like this.
<script type="module">
    import init from './your_awesome_game.js'
    init()
</script>
  • 💣
  • Serve this static folder using any webserver.
    • Sample python webserver: python3 -m "http.server" 8080 from inside the out folder will serve it on port 8080
  • Alternatively use GithubPages to host this output folder for free 🎉
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment