46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
fn main() {
|
|
#[cfg(feature = "debug_server")]
|
|
pack_debug_page().unwrap();
|
|
|
|
println!("cargo:rerun-if-changed=main.js");
|
|
println!("cargo:rerun-if-changed=index.html");
|
|
println!("cargo:rerun-if-changed=main.css");
|
|
}
|
|
|
|
#[cfg(feature = "debug_server")]
|
|
fn pack_debug_page() -> Result<(), Box<dyn std::error::Error>> {
|
|
use std::io::Write;
|
|
|
|
use css_minify::optimizations::{Level, Minifier};
|
|
|
|
let js = std::fs::read_to_string("web/main.js").unwrap();
|
|
let html = std::fs::read_to_string("web/index.html").unwrap();
|
|
let css = std::fs::read_to_string("web/main.css").unwrap();
|
|
|
|
let mut out = Vec::new();
|
|
minify_js::minify(
|
|
&minify_js::Session::new(),
|
|
minify_js::TopLevelMode::Global,
|
|
js.as_bytes(),
|
|
&mut out,
|
|
)
|
|
.unwrap();
|
|
let js = std::str::from_utf8(&out)?;
|
|
|
|
let css = Minifier::default().minify(&css, Level::Three).unwrap();
|
|
|
|
let (head, body) = html
|
|
.split_once("<!--INSERT HEAD CONTENT HERE-->")
|
|
.expect("did not find split point in html");
|
|
|
|
let html = minify_html::minify(
|
|
format!("{head}<style>{css}</style><script>{js}</script>{body}").as_bytes(),
|
|
&minify_html::Cfg::spec_compliant(),
|
|
);
|
|
|
|
std::fs::File::create(std::env::var("OUT_DIR").unwrap() + "/minified.html")?
|
|
.write_all(&html)?;
|
|
|
|
Ok(())
|
|
}
|