Skip to content

feat: cjs require destructuring assignment tree shaking#20548

Merged
alexander-akait merged 3 commits intowebpack:mainfrom
ahabhgk:cjs-tree-shaking-require-destructuring
Mar 3, 2026
Merged

feat: cjs require destructuring assignment tree shaking#20548
alexander-akait merged 3 commits intowebpack:mainfrom
ahabhgk:cjs-tree-shaking-require-destructuring

Conversation

@ahabhgk
Copy link
Copy Markdown
Contributor

@ahabhgk ahabhgk commented Feb 27, 2026

Summary

Support analyze const { a } = require("./m") for cjs tree shaking

What kind of change does this PR introduce?

feat

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

No

If relevant, what needs to be documented once your changes are merged or what have you already documented?

None

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 27, 2026

🦋 Changeset detected

Latest commit: 50b5663

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Feb 27, 2026

Merging this PR will degrade performance by 37.67%

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 123 untouched benchmarks
⏩ 18 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory benchmark "json-modules", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 619.7 KB 994.2 KB -37.67%
Memory benchmark "many-modules-commonjs", scenario '{"name":"mode-production","mode":"production"}' 8 MB 10.3 MB -22.84%
Memory benchmark "react", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 864.3 KB 645.1 KB +33.98%

Comparing ahabhgk:cjs-tree-shaking-require-destructuring (50b5663) with main (2019127)

Open in CodSpeed

Footnotes

  1. 18 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.

@alexander-akait alexander-akait merged commit 39933d3 into webpack:main Mar 3, 2026
52 of 55 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 3, 2026

This PR is packaged and the instant preview is available (39933d3).

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@39933d3
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@39933d3
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@39933d3

aryanraj45 added a commit to aryanraj45/webpack that referenced this pull request Mar 5, 2026
Adds three missing test assertions for the feature introduced in webpack#20548:

- aliased destructuring ({ a: renamedA }) marks the original key as used
- aliased context require (template literal) same behavior
- default value destructuring ({ a = 'fallback' }) still marks the key as used
- rest element ({ a, ...rest }) bails the analysis, all exports kept
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