koute / cargo-web

A Cargo subcommand for the client-side Web
Apache License 2.0
1.11k stars 80 forks source link

Add in --watch option #61

Open Pauan opened 6 years ago

Pauan commented 6 years ago

Right now if you use cargo web start it will automatically re-build if the files change, which is great!

But I'm developing a Chrome Extension, so cargo web start doesn't work for me (because the compiled files are loaded into the browser, not displayed on an HTML page).

So it would be great if I could do cargo web build --watch, cargo web deploy --watch, and cargo web test --watch

When using the --watch option it will watch for file changes (just like cargo web start) and will then re-run cargo web build (or cargo web deploy / cargo web test) automatically.

koute commented 6 years ago

Yep. This is something I was planning on adding myself anyway. (:

Right now I'm switching gears a little to stdweb so it will take some time until I can take a stab at this. That said, if you'd like to have this sooner than later you could probably do it yourself without much trouble. Very roughly - move most of the cmd_deploy.rs to a separate function, run it, if the first built succeeds start a loop, instantiate a watcher from the notify crate (see how it's done in cmd_start; here it's simpler since it can just run on the main thread), pass it whatever project.paths_to_watch() returns, wait for changes from the watcher, rebuild and redeploy, loop again.

Pauan commented 6 years ago

@koute Thanks for the tips! I would love to implement this myself, but my harddrive recently got corrupted and I'm still recovering from that. Within a couple days I should have recovered, and then I can take a stab at that.

byw commented 6 years ago

Right now you can use the regular cargo-watch like this:

cargo watch -x "web build"