Simplify cli-config, hotreload -> devtools (drop to 0 deps, fast compile times) (#2975)

* simplify cli-config crate
* clean up configs
* add devtools crate, update cargo imports
* fix serve addr, fix websocket proxy issue
* add comment about opt profiles
* rename hot-reload to devtools
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-09-17 17:18:23 -07:00
1 parent 8203ee571f
commit 3fb1f739d1
58 files changed
+1131 -1654

No files matched your search

+2 -12
View File
@@ -1,13 +1,9 @@
use dioxus_cli_config::{RuntimeCLIArguments, CURRENT_CONFIG};
use dioxus_core::VirtualDom;
use crate::LiveviewRouter;
pub(crate) fn app_title() -> String {
CURRENT_CONFIG
.as_ref()
.map(|c| c.web.app.title.clone())
.unwrap_or_else(|_| "Dioxus Liveview App".to_string())
dioxus_cli_config::app_title().unwrap_or_else(|| "Dioxus Liveview App".to_string())
}
/// A configuration for the LiveView server.
@@ -19,15 +15,9 @@ pub struct Config<R: LiveviewRouter> {
impl<R: LiveviewRouter> Default for Config<R> {
fn default() -> Self {
let address = RuntimeCLIArguments::from_cli()
.map(|args| args.fullstack_address().address())
.unwrap_or(std::net::SocketAddr::V4(std::net::SocketAddrV4::new(
std::net::Ipv4Addr::new(127, 0, 0, 1),
8080,
)));
Self {
address: dioxus_cli_config::fullstack_address_or_localhost(),
router: R::create_default_liveview_router(),
address,
route: "/".to_string(),
}
}
+14 -13
View File
@@ -6,7 +6,6 @@ use crate::{
LiveViewError,
};
use dioxus_core::prelude::*;
use dioxus_hot_reload::DevserverMsg;
use dioxus_html::{EventData, HtmlEvent, PlatformEventData};
use dioxus_interpreter_js::MutationState;
use futures_util::{pin_mut, SinkExt, StreamExt};
@@ -117,10 +116,12 @@ impl<S> LiveViewSocket for S where
///
/// You might need to transform the error types of the web backend into the LiveView error type.
pub async fn run(mut vdom: VirtualDom, ws: impl LiveViewSocket) -> Result<(), LiveViewError> {
#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(feature = "devtools", debug_assertions))]
let mut hot_reload_rx = {
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
dioxus_hot_reload::connect(move |template| _ = tx.send(template));
if let Some(endpoint) = dioxus_cli_config::devserver_ws_endpoint() {
dioxus_devtools::connect(endpoint, move |template| _ = tx.send(template));
}
rx
};
@@ -157,9 +158,9 @@ pub async fn run(mut vdom: VirtualDom, ws: impl LiveViewSocket) -> Result<(), Li
}
loop {
#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(feature = "devtools", debug_assertions))]
let hot_reload_wait = hot_reload_rx.recv();
#[cfg(not(all(feature = "hot-reload", debug_assertions)))]
#[cfg(not(all(feature = "devtools", debug_assertions)))]
let hot_reload_wait: std::future::Pending<Option<()>> = std::future::pending();
tokio::select! {
@@ -213,22 +214,22 @@ pub async fn run(mut vdom: VirtualDom, ws: impl LiveViewSocket) -> Result<(), Li
}
Some(msg) = hot_reload_wait => {
#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(feature = "devtools", debug_assertions))]
match msg{
DevserverMsg::HotReload(msg)=> {
dioxus_hot_reload::apply_changes(&mut vdom, &msg);
dioxus_devtools::DevserverMsg::HotReload(msg)=> {
dioxus_devtools::apply_changes(&vdom, &msg);
}
DevserverMsg::Shutdown => {
dioxus_devtools::DevserverMsg::Shutdown => {
std::process::exit(0);
},
DevserverMsg::FullReloadCommand
| DevserverMsg::FullReloadStart
| DevserverMsg::FullReloadFailed => {
dioxus_devtools::DevserverMsg::FullReloadCommand
| dioxus_devtools::DevserverMsg::FullReloadStart
| dioxus_devtools::DevserverMsg::FullReloadFailed => {
// usually only web gets this message - what are we supposed to do?
// Maybe we could just binary patch ourselves in place without losing window state?
},
}
#[cfg(not(all(feature = "hot-reload", debug_assertions)))]
#[cfg(not(all(feature = "devtools", debug_assertions)))]
let () = msg;
}
}