use anyhow::Error; use fs_extra::dir::{copy, remove, CopyOptions}; use glob::glob; use html_minifier::minify; use std::{ fs::{read_to_string, File}, io::Write, }; fn main() -> Result<(), Error> { println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=migrations"); println!("cargo:rerun-if-changed=templates"); remove("templates_min")?; copy( "templates", "templates_min", &CopyOptions::new().copy_inside(true), )?; let templates = glob("templates_min/**/*.html")?; for path in templates { let path = path?; if !path.is_file() { continue; } let html = read_to_string(&path)?; let minified = minify(html)?.replace('\n', "").replace(" ", " "); File::create(path)?.write_all(minified.as_bytes())?; } Ok(()) }