diff --git a/Cargo.toml b/Cargo.toml index aa83004..903e972 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,13 +30,7 @@ features = ["web"] [target.'cfg(not(target_arch = "wasm32"))'.dependencies] dioxus-fullstack = { version = "*", features = ["axum"] } -dioxus-cli = { version = "*", optional = true } -railwind = { version = "0.1.5", optional = true } -walkdir = { version = "2.4.0", optional = true } -regex = { version = "1.10.3", optional = true } - -[features] -default = ["auto-build"] -auto-build = ["dep:dioxus-cli", "dep:railwind", "dep:walkdir", "dep:regex"] - -[build-dependencies] +dioxus-cli = "*" +railwind = "0.1.5" +walkdir = "2.4.0" +regex = "1.10.3" diff --git a/src/lib.rs b/src/lib.rs index 224ee59..9215a6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,20 +1,22 @@ +use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; + pub use dioxus::prelude::*; pub use dioxus_fullstack::prelude::*; -#[cfg(all(not(target_arch = "wasm32"), feature = "auto-build"))] +#[cfg(all(not(target_arch = "wasm32"), debug_assertions))] fn build_wasm() { use dioxus_cli::CrateConfig; use railwind::{CollectionOptions, SourceOptions}; use regex::Regex; use std::path::Path; - use std::{env, fs, path::PathBuf}; + use std::{fs, path::PathBuf}; use walkdir::WalkDir; let project_folder = Path::new(env!("CARGO_MANIFEST_DIR")); let output_folder = project_folder.join("web"); // Build WASM - let mut config = CrateConfig::new(None).unwrap(); + let mut config = CrateConfig::new(Some(project_folder.to_path_buf())).unwrap(); config.release = true; config.asset_dir = project_folder.join("assets"); config.out_dir = output_folder.clone(); @@ -50,14 +52,12 @@ pub fn launch< >( component: Component, ) { - #[cfg(all(not(target_arch = "wasm32"), feature = "auto-build"))] - build_wasm(); - #[cfg(target_arch = "wasm32")] LaunchBuilder::new(component).launch(); - #[cfg(all(not(target_arch = "wasm32"), feature = "auto-build"))] + #[cfg(all(not(target_arch = "wasm32"), debug_assertions))] { + build_wasm(); let config = ServeConfigBuilder::new(component, Props::default()) .index_path(concat!(env!("CARGO_MANIFEST_DIR"), "/web/index.html")) .assets_path(concat!(env!("CARGO_MANIFEST_DIR"), "/web")); @@ -65,4 +65,15 @@ pub fn launch< .server_cfg(config) .launch(); } + + #[cfg(all(not(target_arch = "wasm32"), not(debug_assertions)))] + { + let config = ServeConfigBuilder::new(component, Props::default()) + .index_path("web/index.html") + .assets_path("web"); + LaunchBuilder::new(|cx| render!("Hello World")) + .server_cfg(config) + .addr(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 80))) + .launch(); + } }