Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve esMododule exports #1084

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,10 @@ function pitch(request) {
const exportsString = `export { ${identifiers
.map(([id, key]) => `${id} as ${JSON.stringify(key)}`)
.join(", ")} }`;

return `${localsString}\n${exportsString}\n`;
const exportDefaultString = `export default { ${identifiers
.map(([id, key]) => `${JSON.stringify(key)}: ${id}`)
.join(", ")} }`;
return `${localsString}\n${exportsString}\n${exportDefaultString}\n`;
}

return `\n${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ cnA: () => (/* binding */ _1),
/* harmony export */ cnB: () => (/* binding */ _2)
/* harmony export */ cnB: () => (/* binding */ _2),
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
Copy link
Member

Choose a reason for hiding this comment

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

We still need an option for this, otherwise we generate extra content, it is bad for a size

Copy link
Member

Choose a reason for hiding this comment

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

/cc @jantimon

/* harmony export */ });
// extracted by mini-css-extract-plugin
var _1 = () => "class-name-a";
var _2 = () => "class-name-b";

/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "cnA": _1, "cnB": _2 });


/***/ })
Expand Down
9 changes: 7 additions & 2 deletions test/cases/es-module-concatenation-modules/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ __webpack_require__.d(__webpack_exports__, {
var a_namespaceObject = {};
__webpack_require__.r(a_namespaceObject);
__webpack_require__.d(a_namespaceObject, {
a: () => (_1)
a: () => (_1),
"default": () => (a)
});

// NAMESPACE OBJECT: ./b.css
var b_namespaceObject = {};
__webpack_require__.r(b_namespaceObject);
__webpack_require__.d(b_namespaceObject, {
b: () => (b_1)
b: () => (b_1),
"default": () => (b)
});

// NAMESPACE OBJECT: ./index.js
Expand All @@ -71,16 +73,19 @@ __webpack_require__.d(index_namespaceObject, {
// extracted by mini-css-extract-plugin
var _1 = "foo__a";

/* harmony default export */ const a = ({ "a": _1 });

;// CONCATENATED MODULE: ./b.css
// extracted by mini-css-extract-plugin
var b_1 = "foo__b";

/* harmony default export */ const b = ({ "b": b_1 });

;// CONCATENATED MODULE: ./c.css
// extracted by mini-css-extract-plugin
var c_1 = "foo__c";

/* harmony default export */ const c = ({ "c": c_1 });

;// CONCATENATED MODULE: ./index.js
/* eslint-disable import/no-namespace */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "a-class": () => (/* binding */ _1),
/* harmony export */ b__class: () => (/* binding */ _2),
/* harmony export */ cClass: () => (/* binding */ _3)
/* harmony export */ cClass: () => (/* binding */ _3),
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
// extracted by mini-css-extract-plugin
var _1 = "Xh041yLR4iCP4RGjge50";
var _2 = "NMuRsxoDwvW8BhSXhFAY";
var _3 = "ayWIv09rPsAqE2JznIsI";

/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "a-class": _1, "b__class": _2, "cClass": _3 });


/***/ })
Expand Down
4 changes: 3 additions & 1 deletion test/cases/es-named-export-as-is/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "a-class": () => (/* binding */ _1),
/* harmony export */ b__class: () => (/* binding */ _2),
/* harmony export */ cClass: () => (/* binding */ _3)
/* harmony export */ cClass: () => (/* binding */ _3),
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
// extracted by mini-css-extract-plugin
var _1 = "Xh041yLR4iCP4RGjge50";
var _2 = "NMuRsxoDwvW8BhSXhFAY";
var _3 = "ayWIv09rPsAqE2JznIsI";

/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "a-class": _1, "b__class": _2, "cClass": _3 });


/***/ })
Expand Down
4 changes: 3 additions & 1 deletion test/cases/es-named-export-output-module/expected/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ aClass: () => (/* binding */ _1),
/* harmony export */ bClass: () => (/* binding */ _2),
/* harmony export */ cClass: () => (/* binding */ _3)
/* harmony export */ cClass: () => (/* binding */ _3),
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
// extracted by mini-css-extract-plugin
var _1 = "foo__style__a-class";
var _2 = "foo__style__b__class";
var _3 = "foo__style__cClass";

/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "aClass": _1, "bClass": _2, "cClass": _3 });


/***/ })
Expand Down
4 changes: 3 additions & 1 deletion test/cases/es-named-export/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "a-class": () => (/* binding */ _1),
/* harmony export */ b__class: () => (/* binding */ _2),
/* harmony export */ cClass: () => (/* binding */ _3)
/* harmony export */ cClass: () => (/* binding */ _3),
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
// extracted by mini-css-extract-plugin
var _1 = "foo__style__a-class";
var _2 = "foo__style__b__class";
var _3 = "foo__style__cClass";

/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "a-class": _1, "b__class": _2, "cClass": _3 });


/***/ })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ aClass: () => (/* binding */ _1),
/* harmony export */ bClass: () => (/* binding */ _2),
/* harmony export */ cClass: () => (/* binding */ _3)
/* harmony export */ cClass: () => (/* binding */ _3),
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
// extracted by mini-css-extract-plugin
var _1 = "foo__style__a-class";
var _2 = "foo__style__b__class";
var _3 = "foo__style__cClass";

/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({ "aClass": _1, "bClass": _2, "cClass": _3 });


/***/ })
Expand Down