generated from tipragot/rust
Réglage du problème du mauvais nom de projet #4
36
src/lib.rs
36
src/lib.rs
|
@ -5,13 +5,13 @@ pub use dioxus::prelude::*;
|
||||||
pub use dioxus_fullstack::prelude::*;
|
pub use dioxus_fullstack::prelude::*;
|
||||||
|
|
||||||
#[cfg(all(not(target_arch = "wasm32"), debug_assertions))]
|
#[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() {
|
fn build_app() {
|
||||||
use std::io::{BufRead, BufReader};
|
use std::io::{BufRead, BufReader};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::PathBuf;
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
|
|
||||||
use dioxus_cli::{CrateConfig, ExecutableType};
|
use dioxus_cli::CrateConfig;
|
||||||
use railwind::{CollectionOptions, SourceOptions};
|
use railwind::{CollectionOptions, SourceOptions};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
@ -20,28 +20,24 @@ fn build_app() {
|
||||||
let output_folder = project_folder.join("web");
|
let output_folder = project_folder.join("web");
|
||||||
|
|
||||||
// Get the project name
|
// Get the project name
|
||||||
println!("Project folder: {}", project_folder.display());
|
// let cargo_file =
|
||||||
println!("AAA: {}", env!("CARGO_PKG_NAME"));
|
// fs::File::open(project_folder.join("Cargo.toml")).expect("unable to open
|
||||||
let cargo_file =
|
// Cargo.toml"); let project_name = BufReader::new(cargo_file)
|
||||||
fs::File::open(project_folder.join("Cargo.toml")).expect("unable to open Cargo.toml");
|
// .lines()
|
||||||
let project_name = BufReader::new(cargo_file)
|
// .map_while(Result::ok)
|
||||||
.lines()
|
// .find(|l| l.starts_with("name = "))
|
||||||
.map_while(Result::ok)
|
// .expect("unable to find project name");
|
||||||
.find(|l| l.starts_with("name = "))
|
// let project_name = project_name
|
||||||
.expect("unable to find project name");
|
// .trim_start_matches("name = \"")
|
||||||
let project_name = project_name
|
// .trim_end_matches('"');
|
||||||
.trim_start_matches("name = \"")
|
|
||||||
.trim_end_matches('"');
|
|
||||||
println!("Project name: {}", project_name);
|
|
||||||
|
|
||||||
// Build WASM
|
// 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");
|
.expect("unable to load the project configuration");
|
||||||
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();
|
||||||
config.dioxus_config.web.resource.style = Some(vec![PathBuf::from("style.css")]);
|
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");
|
dioxus_cli::build(&config, false).expect("unable to build webassembly");
|
||||||
let index_content = dioxus_cli::gen_page(&config.dioxus_config, false);
|
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");
|
fs::write(output_folder.join("index.html"), index_content).expect("unable to write index.html");
|
||||||
|
@ -93,8 +89,8 @@ pub fn launch<
|
||||||
{
|
{
|
||||||
build_app();
|
build_app();
|
||||||
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("web/index.html")
|
||||||
.assets_path(concat!(env!("CARGO_MANIFEST_DIR"), "/web"));
|
.assets_path("web");
|
||||||
LaunchBuilder::new(|cx| render!("Hello World"))
|
LaunchBuilder::new(|cx| render!("Hello World"))
|
||||||
.server_cfg(config)
|
.server_cfg(config)
|
||||||
.launch();
|
.launch();
|
||||||
|
|
Loading…
Reference in a new issue