build.rs 884 B

12345678910111213141516171819202122232425
  1. use std::process::Command;
  2. fn main() {
  3. // Only build the frontend in release mode to prevent "cargo check" from being blocked.
  4. if std::env::var("PROFILE").map_or(false, |profile| profile.to_lowercase() == "release") {
  5. let status_install = Command::new("npm")
  6. .arg("install")
  7. .current_dir("../frontend/")
  8. .status()
  9. .expect("Failed to execute npm install.");
  10. if !status_install.success() {
  11. panic!("{:?}", status_install);
  12. }
  13. let status_build = Command::new("npm")
  14. .arg("run")
  15. .arg("build")
  16. .current_dir("../frontend/")
  17. .status()
  18. .expect("Failed to execute npm run build.");
  19. if !status_build.success() {
  20. panic!("{:?}", status_build);
  21. }
  22. println!("cargo:rerun-if-changed=../fronted");
  23. }
  24. }