mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 12:43:08 +00:00
use cli flag instead of feature flag
This commit is contained in:
parent
712d258496
commit
fb7ea5915b
6 changed files with 34 additions and 18 deletions
|
@ -46,12 +46,10 @@ flate2 = "1.0.22"
|
|||
tar = "0.4.38"
|
||||
tower = "0.4.12"
|
||||
|
||||
syn = { version = "1.0", optional = true }
|
||||
dioxus-rsx-interpreter = { path = "../dioxus/packages/rsx_interpreter", optional = true }
|
||||
proc-macro2 = { version = "1.0", features = ["span-locations"], optional = true }
|
||||
syn = { version = "1.0" }
|
||||
dioxus-rsx-interpreter = { path = "../dioxus/packages/rsx_interpreter" }
|
||||
proc-macro2 = { version = "1.0", features = ["span-locations"] }
|
||||
|
||||
[features]
|
||||
hot_reload = ["dioxus-rsx-interpreter", "proc-macro2", "syn"]
|
||||
|
||||
[[bin]]
|
||||
path = "src/main.rs"
|
||||
|
|
|
@ -39,6 +39,11 @@ pub struct ConfigOptsServe {
|
|||
/// Build platform: support Web & Desktop [default: "default_platform"]
|
||||
#[clap(long)]
|
||||
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.
|
||||
|
|
|
@ -18,7 +18,9 @@ impl Serve {
|
|||
let mut crate_config = crate::CrateConfig::new()?;
|
||||
|
||||
// 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() {
|
||||
crate_config.as_example(self.serve.example.unwrap());
|
||||
|
|
|
@ -114,6 +114,7 @@ pub struct CrateConfig {
|
|||
pub executable: ExecutableType,
|
||||
pub dioxus_config: DioxusConfig,
|
||||
pub release: bool,
|
||||
pub hot_reload: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -162,6 +163,7 @@ impl CrateConfig {
|
|||
let executable = ExecutableType::Binary(output_filename);
|
||||
|
||||
let release = false;
|
||||
let hot_reload = false;
|
||||
|
||||
Ok(Self {
|
||||
out_dir,
|
||||
|
@ -173,6 +175,7 @@ impl CrateConfig {
|
|||
executable,
|
||||
release,
|
||||
dioxus_config,
|
||||
hot_reload,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -186,6 +189,11 @@ impl CrateConfig {
|
|||
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) {
|
||||
// if let Some(name) = &options.example {
|
||||
// self.as_example(name.clone());
|
||||
|
|
|
@ -19,5 +19,4 @@ pub use error::*;
|
|||
pub mod logging;
|
||||
pub use logging::*;
|
||||
|
||||
#[cfg(feature = "hot_reload")]
|
||||
pub mod hot_reload;
|
||||
|
|
|
@ -15,20 +15,24 @@ use tower_http::services::fs::{ServeDir, ServeFileSystemResponseBody};
|
|||
use crate::{builder, serve::Serve, CrateConfig, Result};
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
#[cfg(feature = "hot_reload")]
|
||||
mod hot_reload;
|
||||
#[cfg(feature = "hot_reload")]
|
||||
use hot_reload::*;
|
||||
|
||||
struct WsReloadState {
|
||||
update: broadcast::Sender<String>,
|
||||
#[cfg(feature = "hot_reload")]
|
||||
last_file_rebuild: Arc<Mutex<FileMap>>,
|
||||
last_file_rebuild: Option<Arc<Mutex<FileMap>>>,
|
||||
watcher_config: CrateConfig,
|
||||
}
|
||||
|
||||
#[cfg(feature = "hot_reload")]
|
||||
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...");
|
||||
|
||||
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 {
|
||||
update: reload_tx.clone(),
|
||||
|
||||
last_file_rebuild: last_file_rebuild.clone(),
|
||||
last_file_rebuild: Some(last_file_rebuild.clone()),
|
||||
watcher_config: config.clone(),
|
||||
});
|
||||
|
||||
|
@ -186,8 +190,7 @@ pub async fn startup(config: CrateConfig) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "hot_reload"))]
|
||||
pub async fn startup(config: CrateConfig) -> Result<()> {
|
||||
pub async fn startup_default(config: CrateConfig) -> Result<()> {
|
||||
log::info!("🚀 Starting development server...");
|
||||
|
||||
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 {
|
||||
update: reload_tx.clone(),
|
||||
|
||||
last_file_rebuild: None,
|
||||
watcher_config: config.clone(),
|
||||
});
|
||||
|
||||
|
@ -313,9 +318,8 @@ async fn ws_handler(
|
|||
{
|
||||
let _ = Serve::regen_dev_page(&state.watcher_config);
|
||||
}
|
||||
#[cfg(feature = "hot_reload")]
|
||||
{
|
||||
let mut write = state.last_file_rebuild.lock().unwrap();
|
||||
if let Some(file_map) = &state.last_file_rebuild {
|
||||
let mut write = file_map.lock().unwrap();
|
||||
*write = FileMap::new(state.watcher_config.crate_dir.clone());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue