build.rs 877 B

1234567891011121314151617181920212223242526
  1. use std::env;
  2. use std::env::current_dir;
  3. use std::error::Error;
  4. use std::fs::{read_to_string, File};
  5. use std::io::{BufWriter, Write};
  6. use std::path::Path;
  7. pub fn main() -> Result<(), Box<dyn Error>> {
  8. let out_dir = env::var("OUT_DIR")?;
  9. let dest_bundle_umd_path = Path::new(&out_dir).join("tauri.bundle.umd.js");
  10. let mut bundle_umd_file = BufWriter::new(File::create(&dest_bundle_umd_path)?);
  11. let bundle_umd_path = current_dir()?.join("../../api/dist/tauri.bundle.umd.js");
  12. println!("cargo:rerun-if-changed={:?}", bundle_umd_path);
  13. if let Ok(bundle_umd_js) = read_to_string(bundle_umd_path) {
  14. write!(bundle_umd_file, "{}", bundle_umd_js)?;
  15. } else {
  16. write!(
  17. bundle_umd_file,
  18. r#"throw new Error("you are trying to use the global Tauri script but the @tauri-apps/api package wasn't compiled; run `yarn build` first")"#
  19. )?;
  20. }
  21. Ok(())
  22. }