trunk-rs / trunk

Build, bundle & ship your Rust WASM application to the web.
https://trunkrs.dev/
Apache License 2.0
3.49k stars 252 forks source link

SSE | WebSockets for auto-reload (future: HMR) #4

Closed thedodd closed 3 years ago

thedodd commented 4 years ago
jeroenvervaeke commented 3 years ago

I started implementing hot reload for trunk.

I got everything finished (backend wise) but I'm blocked by an open issue with tide, SSE simply doesn't seem to work. Sending a SSE back to the client simply doesn't work. Source

This might be another argument for #81 to switch away to another web server.

thedodd commented 3 years ago

So, now that we’ve got a solid WebSocket impl about to land, we can start building a proper hot reloading mechanism.

A rough design:

Boscop commented 3 years ago

Any idea which bundler for Rust Wasm frontends supports livereload? I tried using trunk serve with tauri dev and trunk rebuilds but my tauri app doesn't reload :/ What can I do to get auto-reloading working? :)

ranile commented 3 years ago

What can I do to get auto-reloading working? :)

Right now, use trunk watch to build and serve the dist directory with a server that supports live reloading. Trunk can't do it for now,

Boscop commented 3 years ago

@hamza1311 Can you recommend a server that supports live reloading that can serve any dist from the CLI? I know browser-sync, but is there another one, maybe one that supports the livereload protocol? :)

ranile commented 3 years ago

@Boscop, take a look at httpwatcher

Boscop commented 3 years ago

@hamza1311 Thanks, but it seems there's no way to proxy my own websocket communication (between backend and frontend) through a different port (like browsersync allows)?

ranile commented 3 years ago

@hamza1311 Thanks, but it seems there's no way to proxy my own websocket communication (between backend and frontend) through a different port (like browsersync allows)?

Unfortunately, I'm not aware of any servers that would do this. If you're willing to do that, I think adding live reloading would be a great addition to trunk

alecandido commented 3 years ago

@Boscop, take a look at httpwatcher

Some time ago I was working at another project of mine for managing slides creation (essentially with reveal.js), and I wanted live reloading. It's not perfect, but it is working, and I took it exactly from httpwatcher, isolating the websocket from everything else:

I'm sorry not to be so expert in websockets + rust, but I'm pretty sure there should be no obstacle in repeating the same.

thedodd commented 3 years ago

Hey folks. Lots of good discussion here. We now have WebSockets support in the Trunk dev server, and we should be clear to begin implementing a mechanism for auto-reload / live-reload. There are a few options for us to consider, however considering the discussion over in #141 I am strongly tempted to say that we should attempt to knock out these two issues as part of the same objective.

thedodd commented 3 years ago

191 is an implementation of this feature (not the HMR part though).

thedodd commented 3 years ago

Support for this has landed as part of #191

hackers267 commented 2 weeks ago

Does trunk support the HMR(Hot Module Replacement). If supported, how to enable it?

ctron commented 2 weeks ago

I am not sure this is applicable here. Seems purely like a webpack thing.