├── .gitignore ├── Cargo.toml ├── LICENSE ├── README.md ├── index.html ├── index.js ├── package-lock.json ├── package.json └── src ├── app.rs └── lib.rs /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | /target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | 12 | node_modules 13 | pkg 14 | .cache 15 | dist 16 | .DS_Store -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "yew-starter" 3 | description = "A template for starting a Yew." 4 | version = "0.1.0" 5 | authors = ["shilinzhu "] 6 | categories = ["gui", "wasm", "web-programming"] 7 | keywords = ["yew", "wasm", "wasm-bindgen", "web", "starter", "template"] 8 | edition = "2018" 9 | readme = "README.md" 10 | repository = "https://github.com/SASUKE40/yew-starter" 11 | license = "MIT" 12 | 13 | [lib] 14 | crate-type = ["cdylib"] 15 | 16 | [dependencies] 17 | wasm-bindgen = "0.2" 18 | yew = "0.16" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Edward Elric 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # yew-starter 2 | 3 | [![Netlify Status](https://api.netlify.com/api/v1/badges/c0ca5dfc-6d7f-4bf4-9f60-2987a9776f35/deploy-status)](https://app.netlify.com/sites/yew-starter/deploys) 4 | 5 | A template for starting a Yew. 6 | 7 | **Live Demo:** https://yew-starter.netlify.com 8 | 9 | # Pre-reqs 10 | 11 | Install rust if necessary 12 | 13 | ``` 14 | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 15 | ``` 16 | 17 | Install node if necessary 18 | 19 | ``` 20 | brew install node 21 | ``` 22 | 23 | # Getting started 24 | 25 | - Clone the repository 26 | 27 | ``` 28 | git clone --depth=1 https://github.com/SASUKE40/yew-starter.git 29 | ``` 30 | 31 | ## Install dependencies 32 | 33 | ``` 34 | cargo install wasm-pack 35 | cargo install cargo-web 36 | npm i 37 | ``` 38 | 39 | ## Local development 40 | 41 | ``` 42 | npm start 43 | # navigate to http://localhost:1234 44 | ``` 45 | 46 | ``` 47 | npm build 48 | ``` 49 | 50 | ## Serve 51 | 52 | ``` 53 | npm i serve -g 54 | serve dist 55 | # navigate to http://localhost:5000 56 | ``` 57 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Yew Starter 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import {run_app} from './Cargo.toml'; 2 | run_app(); 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yew-starter", 3 | "version": "1.0.0", 4 | "description": "A template for starting a Yew.", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "parcel index.html", 8 | "build": "parcel build index.html" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/SASUKE40/yew-starter.git" 13 | }, 14 | "keywords": [ 15 | "yew", 16 | "wasm", 17 | "wasm-bindgen", 18 | "web", 19 | "starter", 20 | "template" 21 | ], 22 | "author": "shilinzhu ", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/SASUKE40/yew-starter/issues" 26 | }, 27 | "homepage": "https://github.com/SASUKE40/yew-starter#readme", 28 | "devDependencies": { 29 | "parcel-bundler": "^1.12.4", 30 | "parcel-plugin-wasm.rs": "^1.2.16" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/app.rs: -------------------------------------------------------------------------------- 1 | use yew::prelude::*; 2 | 3 | pub struct App {} 4 | 5 | pub enum Msg {} 6 | 7 | impl Component for App { 8 | type Message = Msg; 9 | type Properties = (); 10 | 11 | fn create(_: Self::Properties, _: ComponentLink) -> Self { 12 | App {} 13 | } 14 | 15 | fn update(&mut self, _msg: Self::Message) -> ShouldRender { 16 | true 17 | } 18 | 19 | fn change(&mut self, _props: Self::Properties) -> ShouldRender { 20 | true 21 | } 22 | 23 | fn view(&self) -> Html { 24 | html! { 25 |

{ "Hello world!" }

26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | mod app; 2 | 3 | use wasm_bindgen::prelude::*; 4 | 5 | #[wasm_bindgen] 6 | pub fn run_app() -> Result<(), JsValue> { 7 | yew::start_app::(); 8 | Ok(()) 9 | } 10 | --------------------------------------------------------------------------------