Skip to content

Commit

Permalink
feat: support tree shaking
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng committed Dec 23, 2024
1 parent ed3ae97 commit dab14a8
Show file tree
Hide file tree
Showing 16 changed files with 1,395 additions and 555 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions crates/rspack_core/src/build_chunk_graph/code_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
assign_depths(
&mut assign_depths_map,
&compilation.get_module_graph(),
modules.iter().collect(),
modules.iter(),
);
input_entrypoints_and_modules.insert(entry_point, modules);
}
Expand Down Expand Up @@ -1133,7 +1133,8 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on

self.stat_processed_blocks += 1;

let chunk_group_info = self.chunk_group_infos.expect_get(&item.chunk_group_info);
let chunk_group_info: &ChunkGroupInfo =
self.chunk_group_infos.expect_get(&item.chunk_group_info);

let runtime = chunk_group_info.runtime.clone();

Expand Down Expand Up @@ -1538,7 +1539,11 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
return modules.clone();
}

self.extract_block_modules(module.get_root_block(compilation), runtime, compilation);
self.extract_block_modules(
module.get_root_block(&compilation.get_module_graph()),
runtime,
compilation,
);
self
.block_modules_runtime_map
.get::<OptionalRuntimeSpec>(&runtime.cloned().into())
Expand Down Expand Up @@ -1937,11 +1942,10 @@ pub(crate) enum DependenciesBlockIdentifier {
}

impl DependenciesBlockIdentifier {
pub fn get_root_block<'a>(&'a self, compilation: &'a Compilation) -> ModuleIdentifier {
pub fn get_root_block<'a>(&'a self, module_graph: &'a ModuleGraph) -> ModuleIdentifier {
match self {
DependenciesBlockIdentifier::Module(m) => *m,
DependenciesBlockIdentifier::AsyncDependenciesBlock(id) => *compilation
.get_module_graph()
DependenciesBlockIdentifier::AsyncDependenciesBlock(id) => *module_graph
.block_by_id(id)
.expect("should have block")
.parent(),
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/build_chunk_graph/incremental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl CodeSplitter {
continue;
};

parent_cg.children.remove(&chunk_group_ukey);
parent_cg.children.swap_remove_full(&chunk_group_ukey);

if let Some(parent_cgi) = self.chunk_group_info_map.get(parent) {
if let Some(parent_cgi) = self.chunk_group_infos.get_mut(parent_cgi) {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/build_chunk_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ pub(crate) fn build_chunk_graph(compilation: &mut Compilation) -> rspack_error::

#[instrument(skip_all)]
pub(crate) fn build_chunk_graph_new(compilation: &mut Compilation) -> rspack_error::Result<()> {
new_code_splitter::code_split(compilation);
new_code_splitter::code_split(compilation)?;
Ok(())
}
Loading

0 comments on commit dab14a8

Please sign in to comment.