Skip to content

lukethacoder/wasm-web-components-playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


photograph of 3 random crabs in a nice bowl

wasm-web-components

playing around with building Web Components in Rust (via WASM)

Installation

Make sure you have wasm-pack installed.

Install Dependencies

cargo build 

Adding New Components

We are using Workspaces, so you can add a new component by running:

cargo new components/NAME_OF_COMPONENT --lib 

Make sure to add this snippet to the Cargo.toml file for each new component setup.

[lib] crate-type = ["cdylib", "rlib"] [dependencies] custom-elements = { workspace = true } wasm-bindgen.workspace = true web-sys = { version = "0.3", features = [ "Window", "Document", "HtmlElement", "Node", "Text" ]}

Build

To build your web components (before running the dev server), run:

NOTE: each component has its own build command. It might be smart to write a script that builds all of the components in one go?

wasm-pack build --target=web --out-dir '../../pkg/NAME_OF_COMPONENT' components/NAME_OF_COMPONENT 

Development Server

Install microserver and then run it from the root of the project.

microserver -a 127.0.0.1 -p 3000 

This will serve up the index.html file at localhost:3000

NOTE: you can use any other tool to serve up the index.html file locally

About

🦀 Building Web Components using Rust (WASM) - no JS here

Topics

Resources

License

Stars

Watchers

Forks