use std::{
env,
error::Error,
fs::{self, File},
io::Write,
path::Path,
};
use minify_html::{Cfg, minify};
const SOURCE_DIR: &str = "./style/components/";
fn main() -> Result<(), Box<dyn Error>> {
println!("cargo::rerun-if-changed=style/components");
let out_dir = env::var("OUT_DIR")?;
let dest_path = Path::new(&out_dir).join("dioxus-tw-components-style.css");
let mut style = File::create(&dest_path)?;
writeln!(
&mut style,
"/* This file was generated by Dioxus Tailwind Components build script */",
)?;
for f in fs::read_dir(SOURCE_DIR)? {
let f = f?;
if !f.file_type()?.is_file() {
continue;
}
let content = fs::read_to_string(f.path())?;
let mut cfg = Cfg::new();
cfg.keep_comments = true;
cfg.allow_removing_spaces_between_attributes = true;
let minified = minify(content.as_bytes(), &cfg);
write!(&mut style, "{}", String::from_utf8(minified)?)?;
}
Ok(())
}