Skip to content

Commit f024617

Browse files
authored
refactor: emit the CommonJS default export as export default (#21708)
1 parent a0c47cd commit f024617

4 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎.changeset/115-module-library-exports.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": patch
33
---
44

5-
Fix namespace object reexports and string export names in module library output.
5+
Fix namespace object reexports and string export names in module library output and emit a CommonJS entry's default as `export default`.

‎lib/library/ModuleLibraryPlugin.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,14 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
585585
alreadyRenderedExports.add(originalName);
586586
}
587587

588+
if (shortHandedExports.length > 0) {
589+
result.add(`export { ${shortHandedExports.join(", ")} };\n`);
590+
}
591+
588592
// Add default export `__webpack_exports__` statement to keep better compatibility
589593
if (treatAsCommonJs) {
590594
needExportsDeclaration = true;
591-
shortHandedExports.push(`${RuntimeGlobals.exports} as default`);
592-
}
593-
594-
if (shortHandedExports.length > 0) {
595-
result.add(`export { ${shortHandedExports.join(", ")} };\n`);
595+
result.add(`export default ${RuntimeGlobals.exports};\n`);
596596
}
597597

598598
result = this._analyzeUnknownProvidedExports(

‎test/configCases/library/render-order-issue/__snapshots__/ConfigCacheTest.snap‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ __WEBPACK_EXTERNAL_MODULE_externals1_v__;
108108
/******/ let __webpack_exports__ = __webpack_require__(\\"./entry.js\\");
109109
/******/ const __webpack_exports__entry1 = __webpack_exports__.entry1;
110110
/******/ const __webpack_exports__entry2 = __webpack_exports__.entry2;
111-
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2, __webpack_exports__ as default };
111+
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2 };
112+
/******/ export default __webpack_exports__;
112113
/******/
113114
"
114115
`;
@@ -221,7 +222,8 @@ __WEBPACK_EXTERNAL_MODULE_externals1_v__;
221222
/******/ let __webpack_exports__ = __webpack_require__(\\"./entry.js\\");
222223
/******/ const __webpack_exports__entry1 = __webpack_exports__.entry1;
223224
/******/ const __webpack_exports__entry2 = __webpack_exports__.entry2;
224-
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2, __webpack_exports__ as default };
225+
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2 };
226+
/******/ export default __webpack_exports__;
225227
/******/
226228
"
227229
`;
@@ -334,7 +336,8 @@ __WEBPACK_EXTERNAL_MODULE_externals1_v__;
334336
/******/ let __webpack_exports__ = __webpack_require__(\\"./entry.js\\");
335337
/******/ const __webpack_exports__entry1 = __webpack_exports__.entry1;
336338
/******/ const __webpack_exports__entry2 = __webpack_exports__.entry2;
337-
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2, __webpack_exports__ as default };
339+
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2 };
340+
/******/ export default __webpack_exports__;
338341
/******/
339342
"
340343
`;
@@ -447,7 +450,8 @@ __WEBPACK_EXTERNAL_MODULE_externals1_v__;
447450
/******/ let __webpack_exports__ = __webpack_require__(\\"./entry.js\\");
448451
/******/ const __webpack_exports__entry1 = __webpack_exports__.entry1;
449452
/******/ const __webpack_exports__entry2 = __webpack_exports__.entry2;
450-
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2, __webpack_exports__ as default };
453+
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2 };
454+
/******/ export default __webpack_exports__;
451455
/******/
452456
"
453457
`;

‎test/configCases/library/render-order-issue/__snapshots__/ConfigTest.snap‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ __WEBPACK_EXTERNAL_MODULE_externals1_v__;
108108
/******/ let __webpack_exports__ = __webpack_require__(\\"./entry.js\\");
109109
/******/ const __webpack_exports__entry1 = __webpack_exports__.entry1;
110110
/******/ const __webpack_exports__entry2 = __webpack_exports__.entry2;
111-
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2, __webpack_exports__ as default };
111+
/******/ export { __webpack_exports__entry1 as entry1, __webpack_exports__entry2 as entry2 };
112+
/******/ export default __webpack_exports__;
112113
/******/
113114
"
114115
`;

0 commit comments

Comments
 (0)