Skip to content

Commit

Permalink
fix: add defaultExport in empty export
Browse files Browse the repository at this point in the history
  • Loading branch information
houhongxu authored and houhongxu committed Aug 17, 2024
1 parent 3df97b6 commit 69a46dd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ function pitch(request) {
}

const result = (function makeResult() {
const defaultExport =
typeof options.defaultExport !== "undefined"
? options.defaultExport
: false;

if (locals) {
if (namedExport) {
const identifiers = Array.from(
Expand All @@ -281,11 +286,6 @@ function pitch(request) {
.map(([id, key]) => `${id} as ${JSON.stringify(key)}`)
.join(", ")} }`;

const defaultExport =
typeof options.defaultExport !== "undefined"
? options.defaultExport
: false;

return defaultExport
? `${localsString}\n${exportsString}\nexport default { ${identifiers
.map(([id, key]) => `${JSON.stringify(key)}: ${id}`)
Expand All @@ -297,7 +297,9 @@ function pitch(request) {
esModule ? "export default" : "module.exports = "
} ${JSON.stringify(locals)};`;
} else if (esModule) {
return "\nexport {};";
return defaultExport
? "\nexport {};export default {};"
: "\nexport {};";
}
return "";
})();
Expand Down

0 comments on commit 69a46dd

Please sign in to comment.