use cli flag instead of feature flag
This commit is contained in:
1 parent
712d258496
commit
fb7ea5915b
6 files changed
+34
-18
No files matched your search
+3
-5
@@ -46,12 +46,10 @@ flate2 = "1.0.22"
|
|||||||
tar = "0.4.38"
|
tar = "0.4.38"
|
||||||
tower = "0.4.12"
|
tower = "0.4.12"
|
||||||
|
|
||||||
syn = { version = "1.0", optional = true }
|
syn = { version = "1.0" }
|
||||||
dioxus-rsx-interpreter = { path = "../dioxus/packages/rsx_interpreter", optional = true }
|
dioxus-rsx-interpreter = { path = "../dioxus/packages/rsx_interpreter" }
|
||||||
proc-macro2 = { version = "1.0", features = ["span-locations"], optional = true }
|
proc-macro2 = { version = "1.0", features = ["span-locations"] }
|
||||||
|
|
||||||
[features]
|
|
||||||
hot_reload = ["dioxus-rsx-interpreter", "proc-macro2", "syn"]
|
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ pub struct ConfigOptsServe {
|
|||||||
/// Build platform: support Web & Desktop [default: "default_platform"]
|
/// Build platform: support Web & Desktop [default: "default_platform"]
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
pub platform: Option<String>,
|
pub platform: Option<String>,
|
||||||
|
|
||||||
|
/// Build with hot reloading rsx [default: false]
|
||||||
|
#[clap(long)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub hot_reload: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensure the given value for `--public-url` is formatted correctly.
|
/// Ensure the given value for `--public-url` is formatted correctly.
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ impl Serve {
|
|||||||
let mut crate_config = crate::CrateConfig::new()?;
|
let mut crate_config = crate::CrateConfig::new()?;
|
||||||
|
|
||||||
// change the relase state.
|
// change the relase state.
|
||||||
crate_config.with_release(self.serve.release);
|
crate_config
|
||||||
|
.with_release(self.serve.release)
|
||||||
|
.with_hot_reload(self.serve.hot_reload);
|
||||||
|
|
||||||
if self.serve.example.is_some() {
|
if self.serve.example.is_some() {
|
||||||
crate_config.as_example(self.serve.example.unwrap());
|
crate_config.as_example(self.serve.example.unwrap());
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ pub struct CrateConfig {
|
|||||||
pub executable: ExecutableType,
|
pub executable: ExecutableType,
|
||||||
pub dioxus_config: DioxusConfig,
|
pub dioxus_config: DioxusConfig,
|
||||||
pub release: bool,
|
pub release: bool,
|
||||||
|
pub hot_reload: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -162,6 +163,7 @@ impl CrateConfig {
|
|||||||
let executable = ExecutableType::Binary(output_filename);
|
let executable = ExecutableType::Binary(output_filename);
|
||||||
|
|
||||||
let release = false;
|
let release = false;
|
||||||
|
let hot_reload = false;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
out_dir,
|
out_dir,
|
||||||
@@ -173,6 +175,7 @@ impl CrateConfig {
|
|||||||
executable,
|
executable,
|
||||||
release,
|
release,
|
||||||
dioxus_config,
|
dioxus_config,
|
||||||
|
hot_reload,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,6 +189,11 @@ impl CrateConfig {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_hot_reload(&mut self, hot_reload: bool) -> &mut Self {
|
||||||
|
self.hot_reload = hot_reload;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
// pub fn with_build_options(&mut self, options: &BuildOptions) {
|
// pub fn with_build_options(&mut self, options: &BuildOptions) {
|
||||||
// if let Some(name) = &options.example {
|
// if let Some(name) = &options.example {
|
||||||
// self.as_example(name.clone());
|
// self.as_example(name.clone());
|
||||||
|
|||||||
@@ -19,5 +19,4 @@ pub use error::*;
|
|||||||
pub mod logging;
|
pub mod logging;
|
||||||
pub use logging::*;
|
pub use logging::*;
|
||||||
|
|
||||||
#[cfg(feature = "hot_reload")]
|
|
||||||
pub mod hot_reload;
|
pub mod hot_reload;
|
||||||
+15
-11
@@ -15,20 +15,24 @@ use tower_http::services::fs::{ServeDir, ServeFileSystemResponseBody};
|
|||||||
use crate::{builder, serve::Serve, CrateConfig, Result};
|
use crate::{builder, serve::Serve, CrateConfig, Result};
|
||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
#[cfg(feature = "hot_reload")]
|
|
||||||
mod hot_reload;
|
mod hot_reload;
|
||||||
#[cfg(feature = "hot_reload")]
|
|
||||||
use hot_reload::*;
|
use hot_reload::*;
|
||||||
|
|
||||||
struct WsReloadState {
|
struct WsReloadState {
|
||||||
update: broadcast::Sender<String>,
|
update: broadcast::Sender<String>,
|
||||||
#[cfg(feature = "hot_reload")]
|
last_file_rebuild: Option<Arc<Mutex<FileMap>>>,
|
||||||
last_file_rebuild: Arc<Mutex<FileMap>>,
|
|
||||||
watcher_config: CrateConfig,
|
watcher_config: CrateConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "hot_reload")]
|
|
||||||
pub async fn startup(config: CrateConfig) -> Result<()> {
|
pub async fn startup(config: CrateConfig) -> Result<()> {
|
||||||
|
if config.hot_reload {
|
||||||
|
startup_hot_reload(config).await
|
||||||
|
} else {
|
||||||
|
startup_default(config).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn startup_hot_reload(config: CrateConfig) -> Result<()> {
|
||||||
log::info!("🚀 Starting development server...");
|
log::info!("🚀 Starting development server...");
|
||||||
|
|
||||||
let dist_path = config.out_dir.clone();
|
let dist_path = config.out_dir.clone();
|
||||||
@@ -46,7 +50,7 @@ pub async fn startup(config: CrateConfig) -> Result<()> {
|
|||||||
let ws_reload_state = Arc::new(WsReloadState {
|
let ws_reload_state = Arc::new(WsReloadState {
|
||||||
update: reload_tx.clone(),
|
update: reload_tx.clone(),
|
||||||
|
|
||||||
last_file_rebuild: last_file_rebuild.clone(),
|
last_file_rebuild: Some(last_file_rebuild.clone()),
|
||||||
watcher_config: config.clone(),
|
watcher_config: config.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -186,8 +190,7 @@ pub async fn startup(config: CrateConfig) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "hot_reload"))]
|
pub async fn startup_default(config: CrateConfig) -> Result<()> {
|
||||||
pub async fn startup(config: CrateConfig) -> Result<()> {
|
|
||||||
log::info!("🚀 Starting development server...");
|
log::info!("🚀 Starting development server...");
|
||||||
|
|
||||||
let dist_path = config.out_dir.clone();
|
let dist_path = config.out_dir.clone();
|
||||||
@@ -196,6 +199,8 @@ pub async fn startup(config: CrateConfig) -> Result<()> {
|
|||||||
|
|
||||||
let ws_reload_state = Arc::new(WsReloadState {
|
let ws_reload_state = Arc::new(WsReloadState {
|
||||||
update: reload_tx.clone(),
|
update: reload_tx.clone(),
|
||||||
|
|
||||||
|
last_file_rebuild: None,
|
||||||
watcher_config: config.clone(),
|
watcher_config: config.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -313,9 +318,8 @@ async fn ws_handler(
|
|||||||
{
|
{
|
||||||
let _ = Serve::regen_dev_page(&state.watcher_config);
|
let _ = Serve::regen_dev_page(&state.watcher_config);
|
||||||
}
|
}
|
||||||
#[cfg(feature = "hot_reload")]
|
if let Some(file_map) = &state.last_file_rebuild {
|
||||||
{
|
let mut write = file_map.lock().unwrap();
|
||||||
let mut write = state.last_file_rebuild.lock().unwrap();
|
|
||||||
*write = FileMap::new(state.watcher_config.crate_dir.clone());
|
*write = FileMap::new(state.watcher_config.crate_dir.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user