Skip to content

feat: concatenate CommonJS modules with statically analyzable exports - #14933

Draft
JSerFeng wants to merge 5 commits into
mainfrom
codex/concatenate-commonjs-modules
Draft

feat: concatenate CommonJS modules with statically analyzable exports#14933
JSerFeng wants to merge 5 commits into
mainfrom
codex/concatenate-commonjs-modules

Conversation

@JSerFeng

@JSerFeng JSerFeng commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add the optimization.concatenateModules.commonjs option, which defaults to true when module concatenation is enabled
  • concatenate strict CommonJS modules whose exports can be statically rewritten by hoisting exports.x / module.exports.x into concatenation-scope bindings
  • apply the same safe CommonJS hoisting to modern-module ESM output without registering a module factory wrapper
  • preserve live bindings, nested export assignments, namespace/default interop, and non-identifier export names
  • keep factory-dependent or prototype-sensitive CommonJS modules wrapped, including top-level return, free arguments, delete exports.x, tagged-template call contexts, and exports.__proto__ / Object prototype access
  • honor optimization.concatenateModules.commonjs: false in modern-module output
  • port the upstream config cases and add ordinary and ESM output regression coverage

This ports webpack/webpack#21417. It intentionally does not include the IIFE wrapper behavior from webpack/webpack#21436.

Related links

Validation

  • cargo check -p rspack_plugin_javascript -p rspack_plugin_esm_library -p rspack_plugin_library -p rspack_binding_api
  • cargo test -p rspack --no-run
  • cargo clippy -p rspack_plugin_javascript -p rspack_plugin_esm_library -p rspack_plugin_library -p rspack_binding_api --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • corepack pnpm run build:cli:dev
  • corepack pnpm run lint:js
  • corepack pnpm --dir tests/rspack-test run test -t "concatenate-modules/" (50 passed)
  • corepack pnpm exec rstest EsmOutput.test.js from tests/rspack-test (486 passed)
  • corepack pnpm exec rstest StatsAPI.test.js -t "with-query" from tests/rspack-test

Checklist

  • Tests updated.
  • Documentation updated (configuration types).

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 3f2e2e3 to fix(binding): preserve entry dependency identity (#14964) by harpsealjs

❌ Size increased by 8.00KB from 66.74MB to 66.75MB (⬆️0.01%)

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

⚠️ Note: The latest commit (8859c6a442) does not have baseline artifacts. Using commit a7c0970a30 for baseline comparison instead. If this seems incorrect, please wait a few minutes and try rerunning the workflow.

Found 5 projects in monorepo, 2 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
popular-libs 1.7 MB 552.1 KB 0 0
react-10k 5.6 MB 1.3 MB - -
react-1k 823.1 KB 217.0 KB 0 0
react-5k 2.7 MB 663.8 KB 0 0
ui-components 4.9 MB 1.4 MB +33.0 B (0.0%) +106.0 B (0.0%)
📋 Detailed Reports (Click to expand)

📁 react-10k

Path: ../build-tools-performance/cases/react-10k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 5.6 MB - -
🗜️ Gzip Size 1.3 MB - -
📄 JavaScript 5.6 MB - -
🎨 CSS 21.0 B - -
🌐 HTML 328.0 B - -
📁 Other Assets 0 B - -

📁 ui-components

Path: ../build-tools-performance/cases/ui-components/dist/rsdoctor-data.json

📌 Baseline Commit: a7c0970a30 | PR: #14964

Metric Current Baseline Change
📊 Total Size 4.9 MB 4.9 MB +33.0 B (0.0%)
🗜️ Gzip Size 1.4 MB 1.4 MB +106.0 B (0.0%)
📄 JavaScript 4.8 MB 4.8 MB +33.0 B (0.0%)
🎨 CSS 112.1 KB 112.1 KB 0
🌐 HTML 328.0 B 328.0 B 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: ui-components Bundle Diff

🤖 AI Degradation Analysis (Click to expand)

📊 Size Changes

No significant regressions detected 🎉. (Total bundle delta: +33 bytes / 0.0006%)

🔍 Root Cause Analysis

  • @arco-design/web-react: Internal util modules (mergeProps, raf, throttleByRaf) increased marginally (+52 bytes parsed total).
  • react-is: Minor increase in parsed size (720 → 745 bytes, +3.47%).
  • @mui/utils: Negligible decrease (-12 bytes parsed) offsetting other changes.
  • No new dependencies or large modules added.

⚠️ Risk Assessment

Overall severity: Low

  • The total initial JS chunk increased by only 33 bytes (5,007,425 → 5,007,458), which is within standard build variance noise.

💡 Optimization Suggestions

  1. Approve PR: No performance impact detected; safe to merge.
  2. Monitor Arco Updates: Keep an eye on @arco-design/web-react changelogs if future updates show larger deltas.
  3. Audit react-is: Ensure it remains a transitive dependency and isn't being directly imported unnecessarily.

Analysis by qwen3.5-plus

Generated by Rsdoctor GitHub Action

@codspeed-hq

codspeed-hq Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 46 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing codex/concatenate-commonjs-modules (3f2e2e3) with main (a7c0970)

Open in CodSpeed

Footnotes

  1. 47 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 29, 2026

Copy link
Copy Markdown

Deploying rspack with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3f2e2e3
Status: ✅  Deploy successful!
Preview URL: https://43acc189.rspack-v2.pages.dev
Branch Preview URL: https://codex-concatenate-commonjs-m.rspack-v2.pages.dev

View logs

@hai-x

hai-x commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants