A convenient template for combining Elm and Rust in the front end.
The Rust Toolchain
You will need the standard Rust toolchain, including rustup, rustc, and cargo.
wasm-pack is your one-stop shop for building, testing, and publishing Rust-generated WebAssembly.
cargo-generate helps you get up and running quickly with a new Rust project by leveraging a pre-existing git repository as a template.
Install cargo-generate with this command:
cargo install cargo-generate
cargo-watch allows you to watch for code changes in Rust.
Install cargo-watch with this command:
cargo install cargo-watch
If you already have npm installed, make sure it is up to date with this command:
npm install npm@latest -g
Clone this template
cargo generate --git https://github.com/AlienKevin/elm-rust-template
This should prompt you for the new project's name.
Build Rust into WebAssembly
In the project root:
cargo watch -i .gitignore -i "pkg/*" -s "wasm-pack build"
This should continuously watch for Rust code changes and compile the new version into WebAssembly.
Install web dependencies
Open another terminal and navigate to the
Then install all npm dependencies:
Serve locally for development
Watch for Elm file changes:
npm run watch
Open another terminal, navigate to
and spin up a dev server using webpack:
npm run start
Navigate your Web browser to http://localhost:8080/ and you should see the default page.
All new changes will be automatically reflected on http://localhost:8080/.
Deploy for a new release
In the root directory.
Create an optimized release build from Rust to WebAssembly.
wasm-pack build --release
npm run build
Now you should see a
dist folder within
www similar to this:
www ├── ... ├── dist ├── 0.bootstrap.js ├── 1.bootstrap.js ├── 27911fde1b082c3d4.module.wasm ├── bootstrap.js ├── index.html ├── ...
Publish to Github Pages
Follow all the previous steps outlined in deployment instructions. Then push the
www/dist folder to the
gh-pages branch on GitHub.
git subtree push --prefix www/dist origin gh-pages
Examples using elm-rust-template
Hack Assembler: An assembler for the Hack assembly language