Skip to content

Commit 2e2aa2b

Browse files
Jinjiangyyx990803
authored andcommitted
feat: support named exports (#1087)
close #1080
1 parent 81a59ba commit 2e2aa2b

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lib/loader.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,14 @@ module.exports = function (content) {
273273
if (script) {
274274
if (options.esModule) {
275275
output += script.src
276-
? getImportForImport('script', script)
277-
: getImport('script', script) + '\n'
276+
? (
277+
getNamedExportForImport('script', script) + '\n' +
278+
getImportForImport('script', script)
279+
)
280+
: (
281+
getNamedExport('script', script) + '\n' +
282+
getImport('script', script)
283+
) + '\n'
278284
} else {
279285
output +=
280286
'var __vue_script__ = ' +
@@ -429,6 +435,7 @@ module.exports = function (content) {
429435
' })\n'
430436
output += '})()}\n'
431437
}
438+
432439
// final export
433440
if (options.esModule) {
434441
output += '\nexport default Component.exports\n'
@@ -461,6 +468,13 @@ module.exports = function (content) {
461468
)
462469
}
463470

471+
function getNamedExport (type, part, index, scoped) {
472+
return (
473+
'export * from ' +
474+
getRequireString(type, part, index, scoped)
475+
)
476+
}
477+
464478
function getRequireString (type, part, index, scoped) {
465479
return loaderUtils.stringifyRequest(
466480
loaderContext,
@@ -486,6 +500,13 @@ module.exports = function (content) {
486500
)
487501
}
488502

503+
function getNamedExportForImport (type, impt, scoped) {
504+
return (
505+
'export * from ' +
506+
getRequireForImportString(type, impt, scoped)
507+
)
508+
}
509+
489510
function getRequireForImportString (type, impt, scoped) {
490511
return loaderUtils.stringifyRequest(
491512
loaderContext,

0 commit comments

Comments
 (0)