generated from tipragot/rust
Réglage du problème du mauvais nom de projet #4
30
src/lib.rs
30
src/lib.rs
|
@ -5,40 +5,26 @@ 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::fs;
|
||||
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;
|
||||
|
||||
let project_folder = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
let project_folder = env::current_dir().expect("unable to get current directory");
|
||||
let output_folder = project_folder.join("web");
|
||||
|
||||
// Get the 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");
|
||||
|
@ -90,8 +76,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