-
-
Notifications
You must be signed in to change notification settings - Fork 756
feat: splitChunks for EsmLibraryPlugin #12521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for rspack ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
a73a0ef to
a6f3280
Compare
There was a problem hiding this 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.
crates/rspack_binding_api/src/raw_options/raw_builtins/raw_esm_lib.rs
Outdated
Show resolved
Hide resolved
crates/rspack_binding_api/src/raw_options/raw_builtins/raw_esm_lib.rs
Outdated
Show resolved
Hide resolved
crates/rspack_binding_api/src/raw_options/raw_builtins/raw_esm_lib.rs
Outdated
Show resolved
Hide resolved
tests/rspack-test/esmOutputCases/split-chunks/merge-dependencies/__snapshots__/esm.snap.txt
Show resolved
Hide resolved
📦 Binary Size-limit
❌ Size increased by 100.38KB from 47.88MB to 47.98MB (⬆️0.20%) |
Rsdoctor Bundle Diff AnalysisFound 5 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
92e2c13 to
2897669
Compare
CodSpeed Performance ReportMerging #12521 will not alter performanceComparing Summary
Footnotes
|
e24f9db to
e986b6e
Compare
e986b6e to
d424390
Compare
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
d424390 to
7b22e3a
Compare
Summary
Merge dependencies
optimization.splitChunksforEsmLibraryPluginshould be separate from originalSplitChunksPlugin, 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:
So we should make sure that
b's dependencycis split into the new chunk as well.Ignore useless config
There are some configs of
optimization.splitChunksare not supported. For example themaxInitialRequestsandmaxSize, 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 itRelated links
Checklist