Skip to content

fix: improve CommonJs bundle to ESM library#19847

Merged
alexander-akait merged 2 commits intomainfrom
cjs-to-esm-2
Sep 1, 2025
Merged

fix: improve CommonJs bundle to ESM library#19847
alexander-akait merged 2 commits intomainfrom
cjs-to-esm-2

Conversation

@hai-x
Copy link
Copy Markdown
Member

@hai-x hai-x commented Aug 28, 2025

What kind of change does this PR introduce?

Part of fix 💎Nice CommonJS modules are converted to ESM and also includes some refactoring to ExportPropertyLibraryPlugin/ModuleLibraryPlugin.

When the entry module is commonjs, we now generate default export pointing to webpack_exports, along with all named exports, aligning with the behavior of cjs-module-lexer.

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

No

What needs to be documented once your changes are merged?

No

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Aug 28, 2025

CodSpeed Performance Report

Merging #19847 will degrade performances by 64.41%

Comparing cjs-to-esm-2 (dab417f) with main (6ae1330)

Summary

❌ 1 regressions
✅ 41 untouched benchmarks

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

Benchmarks breakdown

Benchmark BASE HEAD Change
benchmark "devtool-eval", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 43 ms 120.8 ms -64.41%

@hai-x hai-x changed the title fix: improve cjs bundle to ESM library fix: improve commonjs bundle to ESM library Aug 29, 2025
@hai-x hai-x marked this pull request as ready for review August 29, 2025 15:46
parser.state.module.addDependency(dep);
/** @type {BuildMeta} */ (
parser.state.module.buildMeta
).treatAsCommonjs = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's rename treatAsCommonjs to treatAsCommonJs 😄

@hai-x hai-x changed the title fix: improve commonjs bundle to ESM library fix: improve CommonJs bundle to ESM library Aug 29, 2025
@alexander-akait alexander-akait merged commit 47e80b5 into main Sep 1, 2025
80 of 82 checks passed
@alexander-akait alexander-akait deleted the cjs-to-esm-2 branch September 1, 2025 12:25
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.

ESM Module Output

2 participants