wip: handle vite tooling manually

This commit is contained in:
Alexander Navarro 2025-04-25 16:53:44 -04:00
parent 9c1a8f030c
commit e8f111c2ff
11 changed files with 134 additions and 71 deletions

View file

@ -1,24 +1,27 @@
use std::fs;
use std::path::Path;
fn main() {
let out_dir = std::env::var("OUT_DIR").unwrap();
// we only need to bundle the templates with the
// feature is enabled.
#[cfg(not(debug_assertions))]
#[cfg(feature = "vite")]
{
let out_dir = if cfg!(feature = "embed") {
std::env::var("OUT_DIR").unwrap()
} else {
format!("../../{}", std::env::var("CPD_PUBLIC_DIR").unwrap_or(String::from("public")))
};
std::process::Command::new("bun")
.args(&["vite", "build", "--outDir", &out_dir])
.status()
.unwrap();
minijinja_embed::embed_templates!("frontend/templates");
}
#[cfg(debug_assertions)]
println!("cargo::rerun-if-changed=frontend/assets");
println!("cargo::rerun-if-changed=frontend/static");
println!("cargo::rerun-if-env-changed=CPD_PUBLIC_DIR");
println!("cargo::rerun-if-env-changed=CARGO_FEATURE_EMBED");
}
println!("cargo::rerun-if-env-changed=CARGO_FEATURE_VITE");
#[cfg(feature = "embed")]
{
// dummy file to satisfy the compiler in dev builds
let dest_path = Path::new(&out_dir).join(".vite/manifest.json");
fs::create_dir_all(dest_path.parent().unwrap()).unwrap();
fs::write(&dest_path, "{}").unwrap();
minijinja_embed::embed_templates!("frontend/templates");
println!("cargo::rerun-if-changed=frontend/templates");
}
}