Skip to content

Commit

Permalink
Fix bundling of assets folder
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed Dec 23, 2024
1 parent 5954cbd commit 31993e6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/web/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::{
path::{Path, PathBuf},
};

use anyhow::Context;

use crate::{external_cli::cargo::metadata::Metadata, run::BinTarget};

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -101,32 +103,37 @@ pub fn create_web_bundle(
fs::copy(
linked.build_artifact_path.join(&linked.wasm_file_name),
base_path.join("build").join(&linked.wasm_file_name),
)?;
)
.context("failed to copy WASM artifact")?;
fs::copy(
linked.build_artifact_path.join(&linked.js_file_name),
base_path.join("build").join(&linked.js_file_name),
)?;
)
.context("failed to copy JS artifact")?;

// Assets
if let Some(assets_path) = linked.assets_path {
let new_assets_path = base_path.join("assets");
fs::create_dir_all(&new_assets_path)?;
fs_extra::dir::copy(
assets_path,
base_path.join("assets"),
&new_assets_path,
&fs_extra::dir::CopyOptions {
overwrite: true,
..Default::default()
},
)?;
)
.context("failed to copy assets")?;
}

// Index
let index_path = base_path.join("index.html");
match linked.index {
Index::Folder(path) => {
fs::copy(path, index_path)?;
fs::copy(path, index_path).context("failed to copy custom web assets")?;
}
Index::Static(contents) => {
fs::write(index_path, contents)?;
fs::write(index_path, contents).context("failed to create index.html")?;
}
}

Expand Down

0 comments on commit 31993e6

Please sign in to comment.