Comments (8)
Totally agree that the docs need to be much clearer. I think this might be more of an examples issue than a docs issue
Edited to remove incorrect statement about tooling
from docs.
No it's definitely a docs issue, it doesn't say where the main.js
comes from
See here: https://github.com/yewstack/yew-wasm-pack-minimal/blob/master/main.js
from docs.
Thank you, with that file, I eventually got it working.
- Add
main.js
to the project root:
import init, { run_app } from './pkg/todomvc.js';
async function main() {
await init('/pkg/todomvc_bg.wasm');
run_app();
}
main()
- Add the
wasm-bindgen
dependency toCargo.toml
and the following function tosrc/lib.rs
:
use wasm_bindgen::prelude;
#[wasm_bindgen]
pub fn run_app() -> Result<(), JsValue> {
yew::start_app::<Model>();
Ok(())
}
- Run
rollup main.js --file pkg/bundle.js --format iife
- In
static/index.html
, change the line
<script src="/todomvc.js"></script>
to
<script src="../pkg/bundle.js"></script>
- Run
python -m http.server 8000 --directory static
Is this how the examples are intended to be built and run? In that case, I can try fixing them up and expanding the documentation.
from docs.
Honestly, it's hard to answer that.
I'm not a big fan of the wasm-pack
experience. It works well enough with webpack.. but on its own, not great. It would be nice if it supported binary crates, for one. Then you wouldn't need to add that lib stuff to the Cargo.toml
and add an extra run_app
method. Furthermore, it should bundle the JS for you without needing rollup
. These shortcomings are part of the reason I think we should have a new CLI tool specifically for web apps. (wasm-pack
was originally created for packaging up wasm into npm modules)
I think for the examples we can get by with a script that calls wasm-bindgen
for you. Check out https://github.com/yewstack/yew/tree/master/examples/multi_thread for an idea of how that would work.
For the docs, we should add your steps that you've laid out since the "Using wasm-pack" section is totally broken. Do you mind fixing that?
from docs.
No, I can do that. Should I refer to the wasm-pack-minimal
template?
Also, what would you say is the best way to actually produce a frontend app? The wasm-bindgen
method you posted above?
from docs.
Best is too subjective IMO. My personal app uses webpack
+ wasm-pack
but that's just because I'm really familiar with webpack
.
I don't think Yew needs to give a strong recommendation at this point. I think the ideal solution is basically laid out here: yewstack/yew#1086
from docs.
I finally got around to trying one of the examples (the todomvc
one, again) with the wasm-bindgen
method from https://github.com/yewstack/yew/tree/master/examples/multi_thread. Dear lord, that was so easy. The docs for wasm-bindgen
are currently nonexistent, would that multi_thread
example be a good starting point for writing some?
from docs.
I remember an issue I had getting started with wasm-pack/rollup where the problem turned out to be the Node version I was using. I had to tell NVM to use a much more recent version than the system version, but this was not at all clear from the error message I got. Maybe specifying a minimum Node version in the Getting Started section would be nice.
from docs.
Related Issues (20)
- Introduce a max line length.
- How do we build examples? HOT 2
- Error in one of pages about Properties HOT 2
- I think it's batch_callback, not send_message_batch. HOT 1
- Explain how to setup a wasm-bindgen build environment
- Sample app does not work with web-sys HOT 1
- [doc] toml config make an error. HOT 1
- Use doc-comment to check code snippets HOT 1
- Cant build HOT 2
- Improve documentation around ComponentLink usage
- Home page in chinese HOT 1
- Add instructions for how to produce small release binaries
- Update wasm-bindgen / wasm-pack description
- Spellchecker script.
- Custom website. HOT 5
- Adoptation of a formal style guide
- 'Events' vs 'Callbacks' in the documentation HOT 5
- Document dynamic tags in html section HOT 1
- Add an explanation of the WebSocket service.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docs.