generated from tipragot/rust
This commit is contained in:
parent
55baadf979
commit
8c3b6b98f2
36
src/lib.rs
36
src/lib.rs
|
@ -5,13 +5,13 @@ pub use dioxus::prelude::*;
|
|||
pub use dioxus_fullstack::prelude::*;
|
||||
|
||||
#[cfg(all(not(target_arch = "wasm32"), debug_assertions))]
|
||||
/// Compile le site en webassembly et génaire le fichier de style avec tailwind.
|
||||
/// Compile le site en webassembly et génère le fichier de style avec tailwind.
|
||||
fn build_app() {
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::PathBuf;
|
||||
use std::{env, fs};
|
||||
|
||||
use dioxus_cli::{CrateConfig, ExecutableType};
|
||||
use dioxus_cli::CrateConfig;
|
||||
use railwind::{CollectionOptions, SourceOptions};
|
||||
use regex::Regex;
|
||||
use walkdir::WalkDir;
|
||||
|
@ -20,28 +20,24 @@ fn build_app() {
|
|||
let output_folder = project_folder.join("web");
|
||||
|
||||
// Get the project name
|
||||
println!("Project folder: {}", project_folder.display());
|
||||
println!("AAA: {}", env!("CARGO_PKG_NAME"));
|
||||
let cargo_file =
|
||||
fs::File::open(project_folder.join("Cargo.toml")).expect("unable to open Cargo.toml");
|
||||
let project_name = BufReader::new(cargo_file)
|
||||
.lines()
|
||||
.map_while(Result::ok)
|
||||
.find(|l| l.starts_with("name = "))
|
||||
.expect("unable to find project name");
|
||||
let project_name = project_name
|
||||
.trim_start_matches("name = \"")
|
||||
.trim_end_matches('"');
|
||||
println!("Project name: {}", project_name);
|
||||
// let cargo_file =
|
||||
// fs::File::open(project_folder.join("Cargo.toml")).expect("unable to open
|
||||
// Cargo.toml"); let project_name = BufReader::new(cargo_file)
|
||||
// .lines()
|
||||
// .map_while(Result::ok)
|
||||
// .find(|l| l.starts_with("name = "))
|
||||
// .expect("unable to find project name");
|
||||
// let project_name = project_name
|
||||
// .trim_start_matches("name = \"")
|
||||
// .trim_end_matches('"');
|
||||
|
||||
// Build WASM
|
||||
let mut config = CrateConfig::new(Some(project_folder.to_path_buf()))
|
||||
let mut config = CrateConfig::new(Some(project_folder.clone()))
|
||||
.expect("unable to load the project configuration");
|
||||
config.release = true;
|
||||
config.asset_dir = project_folder.join("assets");
|
||||
config.out_dir = output_folder.clone();
|
||||
config.dioxus_config.web.resource.style = Some(vec![PathBuf::from("style.css")]);
|
||||
config.executable = ExecutableType::Binary(project_name.to_string());
|
||||
dioxus_cli::build(&config, false).expect("unable to build webassembly");
|
||||
let index_content = dioxus_cli::gen_page(&config.dioxus_config, false);
|
||||
fs::write(output_folder.join("index.html"), index_content).expect("unable to write index.html");
|
||||
|
@ -93,8 +89,8 @@ pub fn launch<
|
|||
{
|
||||
build_app();
|
||||
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"));
|
||||
.index_path("web/index.html")
|
||||
.assets_path("web");
|
||||
LaunchBuilder::new(|cx| render!("Hello World"))
|
||||
.server_cfg(config)
|
||||
.launch();
|
||||
|
|
Loading…
Reference in a new issue