Système de base pour la création de projets #1

Merged
tipragot merged 6 commits from base into main 2024-01-26 12:07:02 +00:00
Showing only changes of commit 2a8a3a84a7 - Show all commits

View file

@ -5,7 +5,8 @@ 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))]
fn build_wasm() { /// Compile le site en webassembly et génaire le fichier de style avec tailwind.
fn build_app() {
use std::fs; use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -18,19 +19,20 @@ fn build_wasm() {
let output_folder = project_folder.join("web"); let output_folder = project_folder.join("web");
// Build WASM // Build WASM
let mut config = CrateConfig::new(Some(project_folder.to_path_buf())).unwrap(); let mut config = CrateConfig::new(Some(project_folder.to_path_buf()))
.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")]);
dioxus_cli::build(&config, false).unwrap(); 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).unwrap(); fs::write(output_folder.join("index.html"), index_content).expect("unable to write index.html");
// Update style // Update style
let paths: Vec<_> = WalkDir::new(project_folder.join("src")) let paths: Vec<_> = WalkDir::new(project_folder.join("src"))
.into_iter() .into_iter()
.map(|e| e.unwrap()) .filter_map(|e| e.ok())
.filter(|e| e.file_type().is_file()) .filter(|e| e.file_type().is_file())
.map(|e| e.into_path()) .map(|e| e.into_path())
.collect(); .collect();
@ -38,12 +40,17 @@ fn build_wasm() {
.iter() .iter()
.map(|p| SourceOptions { .map(|p| SourceOptions {
input: p, input: p,
option: CollectionOptions::Regex(Regex::new(r#"class: "([^"]+)""#).unwrap()), option: CollectionOptions::Regex(
Regex::new(r#"class: "([^"]+)""#).expect("unable to create a regex"),
),
}) })
.collect(); .collect();
railwind::parse_to_file( railwind::parse_to_file(
railwind::Source::Files(files), railwind::Source::Files(files),
output_folder.join("style.css").to_str().unwrap(), output_folder
.join("style.css")
.to_str()
.expect("unsupported path"),
true, true,
&mut Vec::new(), &mut Vec::new(),
) )
@ -67,7 +74,7 @@ pub fn launch<
#[cfg(all(not(target_arch = "wasm32"), debug_assertions))] #[cfg(all(not(target_arch = "wasm32"), debug_assertions))]
{ {
build_wasm(); 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(concat!(env!("CARGO_MANIFEST_DIR"), "/web/index.html"))
.assets_path(concat!(env!("CARGO_MANIFEST_DIR"), "/web")); .assets_path(concat!(env!("CARGO_MANIFEST_DIR"), "/web"));