Skip to content
Merged
Changes from 1 commit
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
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