Skip to content

Commit

Permalink
chore: improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
inottn committed Dec 2, 2024
1 parent 24a0765 commit 65cedee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
52 changes: 24 additions & 28 deletions crates/rspack_plugin_html/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,30 @@ impl HtmlPluginAssets {
let mut asset_map = HashMap::new();
assets.public_path = public_path.to_string();

let filtered_entry_names = compilation
.entrypoints
.keys()
.filter(|&entry_name| {
let mut included = true;
if let Some(included_chunks) = &config.chunks {
included = included_chunks.iter().any(|c| c.eq(entry_name));
}
if let Some(exclude_chunks) = &config.exclude_chunks {
included = included && !exclude_chunks.iter().any(|c| c.eq(entry_name));
}
included
})
.collect::<Vec<_>>();

let sorted_entry_names = match config.chunks_sort_mode {
HtmlChunkSortMode::Auto => filtered_entry_names,
HtmlChunkSortMode::Manual => config
.chunks
.as_ref()
.map(|chunks| {
chunks
.iter()
.filter(|&name| compilation.entrypoints.contains_key(name))
.collect()
})
.unwrap_or(filtered_entry_names),
};
let sorted_entry_names: Vec<&String> =
if matches!(config.chunks_sort_mode, HtmlChunkSortMode::Manual)
&& let Some(chunks) = &config.chunks
{
chunks
.iter()
.filter(|&name| compilation.entrypoints.contains_key(name))
.collect()
} else {
compilation
.entrypoints
.keys()
.filter(|&entry_name| {
let mut included = true;
if let Some(included_chunks) = &config.chunks {
included = included_chunks.iter().any(|c| c.eq(entry_name));
}
if let Some(exclude_chunks) = &config.exclude_chunks {
included = included && !exclude_chunks.iter().any(|c| c.eq(entry_name));
}
included
})
.collect()
};

let included_assets = sorted_entry_names
.iter()
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_plugin_html/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(box_patterns)]
#![feature(let_chains)]

pub mod asset;
pub mod config;
Expand Down

0 comments on commit 65cedee

Please sign in to comment.