|
1 | | -## About |
| 1 | +This project contains a minimal [Progressive Web App (PWA)](https://en.wikipedia.org/wiki/Progressive_web_application) using [`Yew`](https://github.com/yewstack/yew). It is based on the [`yew-wasm-pack-minimal`](https://github.com/yewstack/yew-wasm-pack-minimal) example and James Johnson's [Simple PWA Tutorial](https://medium.com/james-johnson/a-simple-progressive-web-app-tutorial-f9708e5f2605). |
2 | 2 |
|
3 | | -This template demonstrates the minimum code and tooling necessary for a frontend web app with simple deployable artifacts consisting of one HTML file, one JavaScript file, and one WebAssembly file, using [`Yew`](https://github.com/yewstack/yew), [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen), and [`wasm-pack`](https://github.com/rustwasm/wasm-pack). |
| 3 | +Compared to [`yew-wasm-pack-minimal`](https://github.com/yewstack/yew-wasm-pack-minimal), the following changes were implemented: |
| 4 | +- Add a manifest file (`manifest.json`) describing the PWA. |
| 5 | +- Add a service worker (`sw.js`) that allows the app to work offline. |
| 6 | +- Add an icon (`icon-256.png`). |
| 7 | +- Register the service worker and manifest file in `index.html`. |
4 | 8 |
|
5 | | -Note: [`yew-wasm-pack-template`](https://github.com/yewstack/yew-wasm-pack-template) is the full-featured counterpart to this template, integrating many common web technologies. |
| 9 | +## Build |
6 | 10 |
|
7 | | -## Usage |
| 11 | +Follow the instructions at https://github.com/yewstack/yew-wasm-pack-minimal to build and bundle the project. Basically: |
| 12 | +``` |
| 13 | +wasm-pack build --target web |
| 14 | +rollup ./main.js --format iife --file ./pkg/bundle.js |
| 15 | +``` |
8 | 16 |
|
9 | | -### 1) Install `Rust` and `wasm-pack` |
| 17 | +## Test / Deploy |
10 | 18 |
|
11 | | -Follow the instructions at https://www.rust-lang.org/tools/install and follow the `installation` link at [`wasm-pack`](https://github.com/rustwasm/wasm-pack). |
| 19 | +PWAs need to be accessed via https. If you don't have a https server set up already, the simplest way to test your PWA is to use Github Pages. Create a new project, activate Github Pages for the master branch and upload the following files to it: |
12 | 20 |
|
13 | | -### 2) Build |
| 21 | +``` |
| 22 | +pkg/bundle.js |
| 23 | +pkg/yew_wasm_pack_minimal_bg.wasm |
| 24 | +icon-256.png |
| 25 | +index.html |
| 26 | +manifest.json |
| 27 | +sw.js |
| 28 | +``` |
14 | 29 |
|
15 | | -Enter `wasm-pack build --target web` from your project's root directory. |
| 30 | +The website should become available under https://USERNAME.github.io/PROJECT_NAME after a couple of minutes. I've uploaded the deployment files to https://github.com/fkohlgrueber/yew-pwa-deploy. The PWA is available under https://fkohlgrueber.github.io/yew-pwa-deploy/. |
16 | 31 |
|
17 | | -### 3) [temporary] Bundle |
18 | | - |
19 | | -Enter `rollup ./main.js --format iife --file ./pkg/bundle.js` from your project's root directory. |
20 | | - |
21 | | -Note: Until `wasm-pack` [RFC #6](https://github.com/rustwasm/rfcs/blob/master/text/006-local-js-dependencies.md) is implemented there is no available option to [generate a single amalgamated JavaScript file](https://github.com/rustwasm/wasm-pack/issues/699). In the interim a bundler, such as [`Rollup`](https://rollupjs.org/guide/en/#quick-start), must be used. |
22 | | - |
23 | | -### 4) [optional] Test Run |
24 | | - |
25 | | -Run a webserver from your project's root directory, such as with the Python 3 command: `python -m http.server 8080`, and load http://localhost:8080/ in a browser to run the app. |
26 | | - |
27 | | -Note: It's expected behavior for the browser console to display an error similar to "WebAssembly.instantiateStreaming failed. Assuming this is because your server does not serve wasm with application/wasm MIME type." Your production webserver should be configured to associate WebAssembly files with the `application/wasm` MIME type. |
28 | | - |
29 | | -### 5) Deploy |
30 | | - |
31 | | -Access your generated build artifacts, `bundle.js` and `yew_wasm_pack_minimal_bg.wasm`, in ./pkg from your project's root directory. |
| 32 | +Feel free to open issues if things don't work for you. |
0 commit comments