collect_assets.rs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. pub fn copy_assets() {
  2. #[cfg(all(
  3. debug_assertions,
  4. any(
  5. target_os = "windows",
  6. target_os = "macos",
  7. target_os = "linux",
  8. target_os = "dragonfly",
  9. target_os = "freebsd",
  10. target_os = "netbsd",
  11. target_os = "openbsd"
  12. )
  13. ))]
  14. {
  15. // The CLI will copy assets to the current working directory
  16. if std::env::var_os("DIOXUS_ACTIVE").is_some() {
  17. return;
  18. }
  19. use manganis_cli_support::AssetManifest;
  20. use manganis_cli_support::AssetManifestExt;
  21. use manganis_cli_support::Config;
  22. use std::path::PathBuf;
  23. let config = Config::current();
  24. let asset_location = config.assets_serve_location();
  25. let asset_location = PathBuf::from(asset_location);
  26. let _ = std::fs::remove_dir_all(&asset_location);
  27. println!("Finding assets... (Note: if you run a dioxus desktop application with the CLI. This process will be significantly faster.)");
  28. let manifest = AssetManifest::load();
  29. let has_assets = manifest
  30. .packages()
  31. .iter()
  32. .any(|package| !package.assets().is_empty());
  33. if has_assets {
  34. println!("Copying and optimizing assets...");
  35. manifest.copy_static_assets_to(&asset_location).unwrap();
  36. println!("Copied assets to {}", asset_location.display());
  37. } else {
  38. println!("No assets found");
  39. }
  40. }
  41. #[cfg(not(all(
  42. debug_assertions,
  43. any(
  44. target_os = "windows",
  45. target_os = "macos",
  46. target_os = "linux",
  47. target_os = "dragonfly",
  48. target_os = "freebsd",
  49. target_os = "netbsd",
  50. target_os = "openbsd"
  51. )
  52. )))]
  53. {
  54. println!(
  55. "Skipping assets in release mode. You compile assets with the dioxus-cli in release mode"
  56. );
  57. }
  58. }