Release mode
Some checks failed
Rust Checks / checks (push) Failing after 4s

This commit is contained in:
Tipragot 2024-01-25 18:13:20 +00:00
parent ae1cc9cc8c
commit 53f2ac8ff8
2 changed files with 22 additions and 17 deletions

View file

@ -30,13 +30,7 @@ features = ["web"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
dioxus-fullstack = { version = "*", features = ["axum"] } dioxus-fullstack = { version = "*", features = ["axum"] }
dioxus-cli = { version = "*", optional = true } dioxus-cli = "*"
railwind = { version = "0.1.5", optional = true } railwind = "0.1.5"
walkdir = { version = "2.4.0", optional = true } walkdir = "2.4.0"
regex = { version = "1.10.3", optional = true } regex = "1.10.3"
[features]
default = ["auto-build"]
auto-build = ["dep:dioxus-cli", "dep:railwind", "dep:walkdir", "dep:regex"]
[build-dependencies]

View file

@ -1,20 +1,22 @@
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
pub use dioxus::prelude::*; pub use dioxus::prelude::*;
pub use dioxus_fullstack::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() { fn build_wasm() {
use dioxus_cli::CrateConfig; use dioxus_cli::CrateConfig;
use railwind::{CollectionOptions, SourceOptions}; use railwind::{CollectionOptions, SourceOptions};
use regex::Regex; use regex::Regex;
use std::path::Path; use std::path::Path;
use std::{env, fs, path::PathBuf}; use std::{fs, path::PathBuf};
use walkdir::WalkDir; use walkdir::WalkDir;
let project_folder = Path::new(env!("CARGO_MANIFEST_DIR")); let project_folder = Path::new(env!("CARGO_MANIFEST_DIR"));
let output_folder = project_folder.join("web"); let output_folder = project_folder.join("web");
// Build WASM // 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.release = true;
config.asset_dir = project_folder.join("assets"); config.asset_dir = project_folder.join("assets");
config.out_dir = output_folder.clone(); config.out_dir = output_folder.clone();
@ -50,14 +52,12 @@ pub fn launch<
>( >(
component: Component<Props>, component: Component<Props>,
) { ) {
#[cfg(all(not(target_arch = "wasm32"), feature = "auto-build"))]
build_wasm();
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
LaunchBuilder::new(component).launch(); 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()) let config = ServeConfigBuilder::new(component, Props::default())
.index_path(concat!(env!("CARGO_MANIFEST_DIR"), "/web/index.html")) .index_path(concat!(env!("CARGO_MANIFEST_DIR"), "/web/index.html"))
.assets_path(concat!(env!("CARGO_MANIFEST_DIR"), "/web")); .assets_path(concat!(env!("CARGO_MANIFEST_DIR"), "/web"));
@ -65,4 +65,15 @@ pub fn launch<
.server_cfg(config) .server_cfg(config)
.launch(); .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();
}
} }