Is your feature request related to a problem? Please describe.
The problem is that someone (like me) unfamiliar with web front-end tooling can't easily get started with Yew, especially while trying to follow the preferred way (webpack + wasm-pack instead of cargo-web).
Describe the solution you'd like
It would be nice to have a beginner-level guide, describing basics of Yew-only (I.e. for project starting with Yew from day 0) minimal set-up with webpack and wasm-pack, one stylesheet and one resource (Like image or favicon). It also would be nice to have minimal instructions for where and how to get webpack and how to use it. This may seem like it's out of scope of Yew documentation, but otherwise users like me will have to learn how webpack works (With JS and stuff) and then bridge this knowledge with knowledge of how to use Yew. This might be a long process, what is not good in my opinion.
Describe alternatives you've considered
Learn how to use webpack with JS? Don't mean to be rude, but no, thanks.
Additional context
None.
Hey @L117 thanks for the issue! This is what we intend for https://github.com/yewstack/yew-wasm-pack-template but ultimately the yew docs should explain this very clearly.
@jstarry I finally figured out what happens in that example. Actually it helped a lot to strip it down. Most confusing parts were (As Q/A for future viewers):
netlify directory can be safely removed.app.rs is just a sub-module.yarn?cargo (a dependency and build system) of JS folks.yarn?npm as well?webpack?webpack?yarn dev dependencies and will be installed into project-local node_modules on build.webpack work?static directory is the web root in that example, just drop some files there.I also spent an entire day figuring out how to make Yew work with web-sys and wasm-pack.
The parts that were most confusing to me as a beginner (feel free to reuse them in a documentation):
#[wasm_bindgen(start)]
pub fn run_app() {
yew::start_app::<Model>();
}
especially to make the examples work, I understand that they have to be able to compile with the stdweb too, so this cannot be in the sources, but at least some comment or a BIG note in docs should exist
wasm-pack build command needs --target web argument to generate a usable .js file<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Yew example</title>
<script type="module">
import init from "./wasm.js"
init()
</script>
</head>
<body></body>
</html>
Where the wasm.js should be replaced with whatever the name of the .js file in the pkg directory created by wasm-pack build is.
https://github.com/yewstack/yew/issues/1139#issuecomment-619594999 - This list is also very Documentation FAQ worthy.
Some more Q/A:
&str into [VNode] (Aka [Html])? (Or anything else, what would render as normal HTML).CRM Example] has more info, but this snippet is enough to get started:/* Inside render function */
let div = {
let div = web_sys::window()
.unwrap()
.document()
.unwrap()
.create_element("div") // It is not required to be "div".
.unwrap();
div.set_inner_html(&self.html_data);
div
};
let node = Node::from(div);
let v_node = VNode::VRef(node);
v_node
```
ComponentLink<Self>][ComponentLink] with name link, [Callback]s, [services], etc?ComponentLink<Self>][ComponentLink] is required. Anything else seems to obey ownership rules (E.g. if timer service gets dropped, it won't call bound callback anymore. If you won't mind such behavior - go ahead). But this will likely change soon.Cargo.toml with error like Custom build command failed. What should I do?yew to latest release. This did the trick for me.
Most helpful comment
Hey @L117 thanks for the issue! This is what we intend for https://github.com/yewstack/yew-wasm-pack-template but ultimately the yew docs should explain this very clearly.