mod.rs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. use crate::plugin::PluginManager;
  2. use super::*;
  3. /// Build the Rust WASM app and all of its assets.
  4. #[derive(Clone, Debug, Parser)]
  5. #[clap(name = "build")]
  6. pub struct Build {
  7. #[clap(flatten)]
  8. pub build: ConfigOptsBuild,
  9. }
  10. impl Build {
  11. pub fn build(self) -> Result<()> {
  12. let mut crate_config = crate::CrateConfig::new()?;
  13. // change the release state.
  14. crate_config.with_release(self.build.release);
  15. crate_config.with_verbose(self.build.verbose);
  16. if self.build.example.is_some() {
  17. crate_config.as_example(self.build.example.unwrap());
  18. }
  19. if self.build.profile.is_some() {
  20. crate_config.set_profile(self.build.profile.unwrap());
  21. }
  22. if self.build.features.is_some() {
  23. crate_config.set_features(self.build.features.unwrap());
  24. }
  25. let platform = self.build.platform.unwrap_or_else(|| {
  26. crate_config
  27. .dioxus_config
  28. .application
  29. .default_platform
  30. .clone()
  31. });
  32. let _ = PluginManager::on_build_start(&crate_config, &platform);
  33. match platform.as_str() {
  34. "web" => {
  35. crate::builder::build(&crate_config, false)?;
  36. }
  37. "desktop" => {
  38. crate::builder::build_desktop(&crate_config, false)?;
  39. }
  40. _ => {
  41. return custom_error!("Unsupported platform target.");
  42. }
  43. }
  44. let temp = gen_page(&crate_config.dioxus_config, false);
  45. let mut file = std::fs::File::create(
  46. crate_config
  47. .crate_dir
  48. .join(
  49. crate_config
  50. .dioxus_config
  51. .application
  52. .out_dir
  53. .clone()
  54. .unwrap_or_else(|| PathBuf::from("dist")),
  55. )
  56. .join("index.html"),
  57. )?;
  58. file.write_all(temp.as_bytes())?;
  59. let _ = PluginManager::on_build_finish(&crate_config, &platform);
  60. Ok(())
  61. }
  62. }