Skip to content

Commit 69a46dd

Browse files
houhongxuhouhongxu
authored and
houhongxu
committed
fix: add defaultExport in empty export
1 parent 3df97b6 commit 69a46dd

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/loader.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ function pitch(request) {
255255
}
256256

257257
const result = (function makeResult() {
258+
const defaultExport =
259+
typeof options.defaultExport !== "undefined"
260+
? options.defaultExport
261+
: false;
262+
258263
if (locals) {
259264
if (namedExport) {
260265
const identifiers = Array.from(
@@ -281,11 +286,6 @@ function pitch(request) {
281286
.map(([id, key]) => `${id} as ${JSON.stringify(key)}`)
282287
.join(", ")} }`;
283288

284-
const defaultExport =
285-
typeof options.defaultExport !== "undefined"
286-
? options.defaultExport
287-
: false;
288-
289289
return defaultExport
290290
? `${localsString}\n${exportsString}\nexport default { ${identifiers
291291
.map(([id, key]) => `${JSON.stringify(key)}: ${id}`)
@@ -297,7 +297,9 @@ function pitch(request) {
297297
esModule ? "export default" : "module.exports = "
298298
} ${JSON.stringify(locals)};`;
299299
} else if (esModule) {
300-
return "\nexport {};";
300+
return defaultExport
301+
? "\nexport {};export default {};"
302+
: "\nexport {};";
301303
}
302304
return "";
303305
})();

0 commit comments

Comments
 (0)