diff --git a/packages/hot-reload/README.md b/packages/hot-reload/README.md index 3ae091179..126c42103 100644 --- a/packages/hot-reload/README.md +++ b/packages/hot-reload/README.md @@ -97,6 +97,15 @@ fn main(){ } ``` +To rebuild the application when the logic changes, you can use the `with_rebuild_command` function on the config builder. This command will be called when hot reloading fails to quickly update the rsx: + +```rust +fn main(){ + hot_reload_init!(Config::new().with_rebuild_command("cargo run")); + // launch your application +} +``` + If you are using a namespace other than html, you can implement the [HotReloadingContext](https://docs.rs/dioxus-rsx/latest/dioxus_rsx/trait.HotReloadingContext.html) trait to provide a mapping between the rust names of your elements/attributes and the resulting strings. You can then provide the Context to the builder to make hot reloading work with your custom namespace: diff --git a/packages/hot-reload/src/lib.rs b/packages/hot-reload/src/lib.rs index fc57b0e56..4e3f56ed7 100644 --- a/packages/hot-reload/src/lib.rs +++ b/packages/hot-reload/src/lib.rs @@ -80,7 +80,7 @@ impl Config { /// Set the command to run to rebuild the project /// /// For example to restart the application after a change is made, you could use `cargo run` - pub const fn with_rebuild_handler(self, rebuild_with: &'static str) -> Self { + pub const fn with_rebuild_command(self, rebuild_with: &'static str) -> Self { Self { rebuild_with: Some(rebuild_with), ..self @@ -198,7 +198,8 @@ pub fn init(cfg: Config) { } execute::shell(rebuild_command) .spawn() - .expect("Failed to rebuild the application. Is cargo installed?"); + .expect("Failed to spawn the rebuild command"); + for channel in &mut *channels.lock().unwrap() { send_msg(HotReloadMsg::Shutdown, channel); } @@ -233,11 +234,12 @@ pub fn init(cfg: Config) { // Give time for the change to take effect before reading the file if !real_paths.is_empty() { - std::thread::sleep(std::time::Duration::from_millis(100)); + std::thread::sleep(std::time::Duration::from_millis(10)); } let mut channels = channels.lock().unwrap(); for path in real_paths { + println!("File changed: {:?}", path); // if this file type cannot be hot reloaded, rebuild the application if path.extension().and_then(|p| p.to_str()) != Some("rs") { rebuild();