feat: support optimization.inlineExports#20973
Conversation
🦋 Changeset detectedLatest commit: 884ad5a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
This PR is packaged and the instant preview is available (1ea4f72). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@1ea4f72
yarn add -D webpack@https://pkg.pr.new/webpack@1ea4f72
pnpm add -D webpack@https://pkg.pr.new/webpack@1ea4f72 |
|
I like this feature, we will bring this in the next minor release |
|
@hai-x Feel free to make ready to review when you resolve merge conflicts, I like this improvement |
|
@alexander-akait Yeah, it's almost ready, just dealing with the snapshot errors to ensure this optimization is correct. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20973 +/- ##
==========================================
+ Coverage 91.67% 91.71% +0.04%
==========================================
Files 573 577 +4
Lines 59874 60307 +433
Branches 16159 16315 +156
==========================================
+ Hits 54888 55313 +425
- Misses 4986 4994 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@hai-x let's skip some tests for globalThis and node@10 |
Types CoverageCoverage after merging inline-exports into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @@ -0,0 +1,3 @@ | |||
| const INLINE_1 = 1; | |||
| import * as reexportedDestructingBarrelSideEffects from "./re-export.destructing-barrel-side-effects.js"; | ||
| import * as constantsCjs from "./constants.cjs"; | ||
| import * as constantsNoInline from "./constants.no-inline.js"; | ||
| import { REMOVE_b as BRANCH_TRUE, REMOVE_FALSE as BRANCH_FALSE } from "./constants.js"; |
| import { REMOVE_b as BRANCH_TRUE, REMOVE_FALSE as BRANCH_FALSE } from "./constants.js"; | ||
|
|
||
| const fs = __non_webpack_require__("fs"); | ||
| const path = __non_webpack_require__("path"); |
|
I want to add more test cases, please do not merge yet. I will finish those test cases today. |
Summary
What kind of change does this PR introduce?
Support
optimization.inlineExportswhich is a new opt-in optimization that inlines ESM exports bound to small primitive constants (≤6-bytenull/undefined/boolean/number/string) at every import site for better tree-shaking.Once every import is replaced with the literal, the import dependency becomes inactive, the export turns unused, and DCE can drop the export — and, when the module is side-effect free, the module itself.
Did you add tests for your changes?
TODO
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?
Yes
Use of AI
Mostly, port from
rspackby claude code.