Fix asset bundling in the CLI (#2145)
* Fix asset bundling in the CLI * fix clippy
This commit is contained in:
1 parent
2ac4bdb673
commit
9942c8bfd1
2 files changed
+25
-15
No files matched your search
@@ -66,7 +66,7 @@ impl Bundle {
|
|||||||
let mut crate_config = dioxus_cli_config::CrateConfig::new(bin)?;
|
let mut crate_config = dioxus_cli_config::CrateConfig::new(bin)?;
|
||||||
|
|
||||||
// change the release state.
|
// change the release state.
|
||||||
crate_config.with_release(self.build.release);
|
crate_config.with_release(true);
|
||||||
crate_config.with_verbose(self.build.verbose);
|
crate_config.with_verbose(self.build.verbose);
|
||||||
|
|
||||||
if self.build.example.is_some() {
|
if self.build.example.is_some() {
|
||||||
@@ -140,17 +140,19 @@ impl Bundle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all assets from collect assets to the bundle
|
// Copy the assets in the dist directory to the bundle
|
||||||
{
|
let static_asset_output_dir = &crate_config.dioxus_config.application.out_dir;
|
||||||
let config = manganis_cli_support::Config::current();
|
// Make sure the dist directory is relative to the crate directory
|
||||||
let location = config.assets_serve_location().to_string();
|
let static_asset_output_dir = static_asset_output_dir
|
||||||
let location = format!("./{}", location);
|
.strip_prefix(&crate_config.crate_dir)
|
||||||
println!("Adding assets from {} to bundle", location);
|
.unwrap_or(static_asset_output_dir);
|
||||||
if let Some(resources) = &mut bundle_settings.resources {
|
|
||||||
resources.push(location);
|
let static_asset_output_dir = static_asset_output_dir.display().to_string();
|
||||||
} else {
|
println!("Adding assets from {} to bundle", static_asset_output_dir);
|
||||||
bundle_settings.resources = Some(vec![location]);
|
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()
|
let mut settings = SettingsBuilder::new()
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ fn assets_head() -> Option<String> {
|
|||||||
))]
|
))]
|
||||||
{
|
{
|
||||||
let head = crate::protocol::get_asset_root_or_default();
|
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) {
|
match std::fs::read_to_string(&head) {
|
||||||
Ok(s) => Some(s),
|
Ok(s) => Some(s),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -142,7 +142,9 @@ pub(super) fn desktop_handler(
|
|||||||
// Else, try to serve a file from the filesystem.
|
// Else, try to serve a file from the filesystem.
|
||||||
match serve_from_fs(path) {
|
match serve_from_fs(path) {
|
||||||
Ok(res) => responder.respond(res),
|
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<Response<Vec<u8>>> {
|
|||||||
|
|
||||||
// If we can't find it, make it absolute and try again
|
// If we can't find it, make it absolute and try again
|
||||||
if !asset.exists() {
|
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() {
|
if !asset.exists() {
|
||||||
|
|||||||
Reference in new issue
Block a user