Skip to content

Conversation

@JSerFeng
Copy link
Contributor

@JSerFeng JSerFeng commented Dec 22, 2025

Summary

Merge dependencies

optimization.splitChunks for EsmLibraryPlugin should be separate from original SplitChunksPlugin, modules in web mode can be split into any chunks, as the execution is handled by __webpack_require__ runtime. This does not correct for Esm output.

Esm executes once chunk is loaded. So any module matches a group, all sub dependencies of the module should also be matches the group to avoid cycle deps. If not, Imagine this:

a -> b -> c

cacheGroup.test: /b/

Then b is extracted to another chunk, but leaves a and c still in the same chunk.

chunk1: [ac]
chunk2: [b]

chunk1 and chunk2 has cycle dependencies

So we should make sure that b's dependency c is split into the new chunk as well.

Ignore useless config

There are some configs of optimization.splitChunks are not supported. For example the maxInitialRequests and maxSize, that is used for improving chunk loading in browser, which is no need for library output. And it's also hard to implement, cause what module need to be split, and when it's split, what to do with its dependencies ? If not care, there must be a cycle, if care, there may be a huge chunk as all dependencies should also in the chunk. So for now we don't implement it

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings December 22, 2025 07:27
@netlify
Copy link

netlify bot commented Dec 22, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit 7b22e3a
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6959e4d0d659480008dfdf7d
😎 Deploy Preview https://deploy-preview-12521--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: feature release: feature related release(mr only) labels Dec 22, 2025
@JSerFeng JSerFeng force-pushed the feat/esm-split-chunks branch from a73a0ef to a6f3280 Compare December 22, 2025 07:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements a specialized splitChunks functionality for EsmLibraryPlugin to handle ESM's unique execution model. Unlike web mode where chunk execution is controlled by __webpack_require__ runtime, ESM chunks execute immediately upon loading, requiring careful dependency management to avoid cyclic dependencies.

Key Changes

  • Implements ESM-specific split chunks logic that ensures dependencies are grouped correctly
  • Adds validation and warnings for unsupported splitChunks configuration options in ESM library mode
  • Refactors existing split chunks code to enable reuse between standard and ESM implementations

Reviewed changes

Copilot reviewed 26 out of 28 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
packages/rspack/src/builtin-plugin/EsmLibraryPlugin.ts Adds unsupported config validation, manages splitChunks options transfer to Rust plugin
packages/rspack/src/builtin-plugin/SplitChunksPlugin.ts Exports toRawSplitChunksOptions for reuse in ESM library plugin
crates/rspack_plugin_esm_library/src/split_chunks.rs New implementation of ESM-specific split chunks logic with dependency merging
crates/rspack_plugin_esm_library/src/plugin.rs Integrates split chunks functionality into EsmLibraryPlugin
crates/rspack_plugin_split_chunks/src/plugin/min_size.rs Refactored to extract ModulesContainer trait and remove_min_size_violating_modules function for reuse
crates/rspack_plugin_split_chunks/src/common.rs Extracts get_module_sizes as public utility function
crates/rspack_plugin_remove_duplicate_modules/src/lib.rs Enhanced with chunk merging optimization logic
crates/rspack_binding_api/src/raw_options/raw_builtins/raw_esm_lib.rs Adds binding support for splitChunks configuration
tests/rspack-test/esmOutputCases/split-chunks/merge-dependencies/* Test case demonstrating dependency merging behavior
tests/rspack-test/statsOutputCases/esm-lib-split-chunks-warning/* Test case for unsupported config warnings

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

📦 Binary Size-limit

Comparing 7b22e3a to refactor: remove option in module_graph_module_by_identifier_mut (#12610) by hardfist

❌ Size increased by 100.38KB from 47.88MB to 47.98MB (⬆️0.20%)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 22, 2025

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
react-10k 5.7 MB 0
react-1k 825.4 KB 0
react-5k 2.7 MB 0
rome 984.3 KB 0
ui-components 2.1 MB 0

Generated by Rsdoctor GitHub Action

@JSerFeng JSerFeng force-pushed the feat/esm-split-chunks branch from 92e2c13 to 2897669 Compare December 22, 2025 07:53
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 22, 2025

CodSpeed Performance Report

Merging #12521 will not alter performance

Comparing feat/esm-split-chunks (7b22e3a) with main (ad4dfd7)

Summary

✅ 16 untouched
⏩ 1 skipped1

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@JSerFeng JSerFeng force-pushed the feat/esm-split-chunks branch 8 times, most recently from e24f9db to e986b6e Compare December 29, 2025 07:39
@JSerFeng JSerFeng force-pushed the feat/esm-split-chunks branch from e986b6e to d424390 Compare December 29, 2025 08:20
JSerFeng and others added 4 commits January 4, 2026 11:54
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@JSerFeng JSerFeng force-pushed the feat/esm-split-chunks branch from d424390 to 7b22e3a Compare January 4, 2026 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants