diff --git a/packages/cli/src/cli/bundle.rs b/packages/cli/src/cli/bundle.rs index 85c21cd21..13a66d855 100644 --- a/packages/cli/src/cli/bundle.rs +++ b/packages/cli/src/cli/bundle.rs @@ -66,7 +66,7 @@ impl Bundle { let mut crate_config = dioxus_cli_config::CrateConfig::new(bin)?; // change the release state. - crate_config.with_release(self.build.release); + crate_config.with_release(true); crate_config.with_verbose(self.build.verbose); if self.build.example.is_some() { @@ -140,17 +140,19 @@ impl Bundle { } } - // Add all assets from collect assets to the bundle - { - let config = manganis_cli_support::Config::current(); - let location = config.assets_serve_location().to_string(); - let location = format!("./{}", location); - println!("Adding assets from {} to bundle", location); - if let Some(resources) = &mut bundle_settings.resources { - resources.push(location); - } else { - bundle_settings.resources = Some(vec![location]); - } + // Copy the assets in the dist directory to the bundle + let static_asset_output_dir = &crate_config.dioxus_config.application.out_dir; + // Make sure the dist directory is relative to the crate directory + let static_asset_output_dir = static_asset_output_dir + .strip_prefix(&crate_config.crate_dir) + .unwrap_or(static_asset_output_dir); + + let static_asset_output_dir = static_asset_output_dir.display().to_string(); + println!("Adding assets from {} to bundle", static_asset_output_dir); + if let Some(resources) = &mut bundle_settings.resources { + resources.push(static_asset_output_dir); + } else { + bundle_settings.resources = Some(vec![static_asset_output_dir]); } let mut settings = SettingsBuilder::new() diff --git a/packages/desktop/src/protocol.rs b/packages/desktop/src/protocol.rs index 7d2c1a8a1..769e81d4d 100644 --- a/packages/desktop/src/protocol.rs +++ b/packages/desktop/src/protocol.rs @@ -82,7 +82,7 @@ fn assets_head() -> Option { ))] { let head = crate::protocol::get_asset_root_or_default(); - let head = head.join("__assets_head.html"); + let head = head.join("dist").join("__assets_head.html"); match std::fs::read_to_string(&head) { Ok(s) => Some(s), Err(err) => { @@ -142,7 +142,9 @@ pub(super) fn desktop_handler( // Else, try to serve a file from the filesystem. match serve_from_fs(path) { Ok(res) => responder.respond(res), - Err(e) => tracing::error!("Error serving request from filesystem {}", e), + Err(e) => { + tracing::error!("Error serving request from filesystem {}", e); + } } } @@ -152,7 +154,13 @@ fn serve_from_fs(path: PathBuf) -> Result>> { // If we can't find it, make it absolute and try again if !asset.exists() { - asset = PathBuf::from("/").join(path); + asset = PathBuf::from("/").join(&path); + } + + // If we can't find it, add the dist directory and try again + // When bundling we currently copy the whole dist directory to the output directory instead of the individual files because of a limitation of cargo bundle2 + if !asset.exists() { + asset = get_asset_root_or_default().join("dist").join(&path); } if !asset.exists() {