rustwasm/rust-webpack-template

How to enable live reloading of Rust code?

dlight opened this issue · 10 comments

Hello, I've found this template with live reloading

https://github.com/rustwasm/rust-webpack-template

But I'm unsure how to integrate with the one on this repo. Is it something on webpack.config.js?

Anyway I think this would be a good feature to have.

Oh, here @xtuc said

Yes, I've added it but we have some issue with the live reload (changes to rust files doesn't trigger the compilation). I'm working on it.

Did it work out?

xtuc commented

Live reloading should work now.

The wasm-pack-plugin plugin (see https://github.com/rustwasm/rust-webpack-template/blob/master/webpack.config.js#L21-L23) does the watching. Does it work for you?

What should I do to trigger live reloading? Is just editing lib.rs sufficient?

I ran the web server with npm run start and edited lib.rs and it didn't trigger a rebuild. (neither a cargo build triggers a live reload). I need to restart the web server to see the changes.

xtuc commented

Are you using this template? It would recompile and reload the page when editing a *.rs file defined in the crateDirectory directory (crate by default).

I am, and it doesn't recompile when editing a *.rs file. :(

But I found out that it live-reloads if I run wasm-pack manually. So the problem is indeed in the WasmPackPlugin bit.

Here npm install warns

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

It seems fsevents is a macOS-only library for watching filesystem events. I'm running Linux; perhaps that's the problem? (but in Linux it should just use inotify..)

xtuc commented

I'm using Linux too and it works, we use the same library that Webpack uses for its watcher, it should be working on all platforms.

Do you see a compilation error ? What happens if you run cargo build in the crate directory by hand?

I secon this. I am on mac. Editing /crate/*.rs does not do anything, unless I restart the server

xtuc commented

Ok so I guess it's a bug
@fitzgen it should probably be "blocking" Rust release?

@xtuc no compilation error. I can edit the crate and issue cargo build just fine (but it won't live reload).

If I run wasm-pack build, it builds fine too; and then webpack live reloads.

I think this is basically the same issue as #69. I have submitted a PR for this in #81, but it waits for a PR in wasm-tool/wasm-pack-plugin#43. I think we should try to reproduce this issue after those PR's have been merged (if they will get merged that is).