Skip to content
This repository was archived by the owner on Jul 19, 2020. It is now read-only.

Latest commit

 

History

History
82 lines (51 loc) · 2.24 KB

build-environment.md

File metadata and controls

82 lines (51 loc) · 2.24 KB

Build Environment

Build Tools

You actually don't need extra build tools to release a Yew application but we recommend them. They make deployment and packaging much less of a headache by generating all of the wrapper JavaScript code necessary to run the .wasm file from your app in the browser.

You can check out the Starter Templates to get up and running quickly or read on to learn more about your options.

wasm-pack

This tool was created by the Rust / Wasm Working Group and is the most actively developed tool for building WebAssembly applications. It supports packaging code into npm modules and has an accompanying Webpack plugin for easy integration with an existing JavaScript application. Find more information here.

{% hint style="info" %} Note that the crate-type in your Cargo.toml will need to be cdylib when using wasm-pack {% endhint %}

Install

cargo install wasm-pack

Build

This command will produce a bundle in the ./pkg directory with your app's compiled WebAssembly along with a JavaScript wrapper which can be used to start your application.

wasm-pack build

Bundle

For more information on Rollup visit this guide

rollup ./main.js --format iife --file ./pkg/bundle.js

Serve

Feel free to use your preferred server. Here we use a simple python server to serve to http://[::1]:8000.

python -m http.server 8000

Supported Targets

  • wasm32-unknown-unknown

cargo-web

Cargo web is a cargo subcommand for building client web apps. It makes building and deploying web applications incredibly easy. It is also the only toolchain that supports Emscripten targets. Read more here.

Install

cargo install cargo-web

Build

cargo web build

Run

cargo web start

Supported Targets

  • wasm32-unknown-unknown
  • wasm32-unknown-emscripten
  • asmjs-unknown-emscripten

{% hint style="info" %} For *-emscripten targets, you'll need to install the Emscripten SDK {% endhint %}