yewstack / yew

Rust / Wasm framework for creating reliable and efficient web applications
https://yew.rs
Apache License 2.0
30.48k stars 1.42k forks source link

Usage of NPM packages #2041

Open Sheap opened 2 years ago

Sheap commented 2 years ago

This is about:

Problem The 3rd point on the yew homepage states:

It supports JavaScript interoperability, allowing developers to leverage NPM packages and integrate with existing JavaScript applications.

How to achieve this does not seem to be documented anywhere, nor any current examples which do it.

In a previous version, there was the "npm_and_rest" example, which appeared to do this with the "ccxt" library. I've tried to replicate that idea for a different library (keycloak-js), but I get errors.

So first of all - is this possible. If it is, can we document how to achieve it?

If it's not possible, we should remove this point.

Questionaire (Optional)

siku2 commented 2 years ago

This point has always been somewhat misleading because Yew makes (almost) no effort in this regard. Interoperability depends on the build system and the bindings library. Nowadays Yew only supports wasm-bindgen bindings, which makes it fairly easy to write Rust bindings for JavaScript libraries. Trunk, to name the most relevant build system, then provides a convenient mechanism to load the library's js code along with the wasm file. So there is something there to back this claim up, but the documentation could be refined and an example provided.

martinitus commented 2 years ago

Couple of minutes after stumbling over this ticket I stumbled over

https://github.com/hobofan/yew-react-example

which is part of the curated link list on:

https://project-awesome.org/jetli/awesome-yew

Maybe that's a starting point, but the example at the moment is still based on yew 0.16.

HtH, Martin

ranile commented 2 years ago

material-yew is good starting point. It won't compile with master Yew but the interoperability code should be the same.

Madoshakalaka commented 2 years ago

I'm working on a library that can help this, see discussion #2213

Madoshakalaka commented 2 years ago

I just release yew-interop, I'll keep the master branch up to date with yew's master branch too, everybody is welcome to try it out!

The example crate in yew-interop can also be a good learning material on how to create rust bindings for javascript API.