Git Product home page Git Product logo

yew-scaffold's Introduction

yew-scaffold - skeleton project for building web assembly applications in rust, using the Yew framework.

This template integrates the following rust projects:

  • wasmbl - wasm build tool that extends wasm builds with bundled assets, custom build specs, etc..
  • ybc - a implementation of bulma components for yew
  • warp - web server framework

 

Using this template


click the 'use this template' button or clone the repository

git clone https://github.com/justenb/yew-wasmbl-bulma-scaffold

install cargo-make

cargo install --force cargo-make

project structure

.
├── frontend      # Yew components 
├── backend       # Warp server and wasm bundler 
├── common        # Workspace shared libs  
├── run           # Custom CLI commands 
├── Dockerfile    # Compile targets in a container
├── index.html    # 
├── Makefile.toml # Build tasks

Development


Starting the dev server

cargo make serve

#( will reload if any changes are made to the frontend )
# default listener is 4000
# use  cargo make --env DOCKER_ID="${your_docker_id}"  serve
# change default bind port.

yew component layout

root component - frontend/src/app.rs

// frontend/src/containers/base.rs

    fn view(&self) -> Html {
        html! {
            <>
            { BaseContainer::view_nav() }
                {self.props.children.clone()}
            { BaseContainer::view_footer() }
            </>
        }
    }

containers - parent components that will persist route changes

// frontend/src/containers/base.rs
    fn view(&self) -> Html {
        html! {
            <>
            { BaseContainer::view_nav() }
                {self.props.children.clone()}
            { BaseContainer::view_footer() }
            </>
        }
    }

pages - yew router targets

// frontend/src/app.rs
match switch {
        AppRouter::RootPath => html!{
            <pages::home::HomePage/>
        },
        ...
}

mounting the app

#[wasm_bindgen(start)]
pub fn start_app() {
    let div = document().query_selector("#app").unwrap().unwrap();
    App::<app::App>::new().mount(div);
}
<!DOCTYPE html>
<html lang="en">
    <head>
        <base href="{{ base_url }}">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        {{ stylesheet | safe }}

        <title>Yew + Bulma Scaffold</title>
    </head>
    <body>
        <div id="app"></div>
        {{ javascript | safe }}
    </body>
</html>

Building your project


compile for local target

cargo make build

build project as a docker image

cargo make --env SERVE_PORT="${expose_port}" publish-docker
# SERVE_PORT defaults to 4000
  • compiles the project in a build container

  • copies the target/release/{build-bin, build/} files from the build to an a alpine container, the current template's final container artifact is < 12MB

Publishing your project


cargo make --env DOCKER_ID="${your_docker_id}" publish-docker

release and push your build as a docker image to your configured container registry ( this task assumes docker is installed and a valid docker config is set )

Todo


  • add more router templates
  • add examples of integrating component state
  • add callback examples
  • suggestions?

I am learning rust and wasm as I go, so please share and contribute! 🎉

yew-scaffold's People

Contributors

zkyzx avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.