Skip to content

Commit

Permalink
feat: support named exports (#1087)
Browse files Browse the repository at this point in the history
close #1080
  • Loading branch information
Jinjiang authored and yyx990803 committed Dec 15, 2017
1 parent 81a59ba commit 2e2aa2b
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/loader.js
Expand Up @@ -273,8 +273,14 @@ module.exports = function (content) {
if (script) {
if (options.esModule) {
output += script.src
? getImportForImport('script', script)
: getImport('script', script) + '\n'
? (
getNamedExportForImport('script', script) + '\n' +
getImportForImport('script', script)
)
: (
getNamedExport('script', script) + '\n' +
getImport('script', script)
) + '\n'
} else {
output +=
'var __vue_script__ = ' +
Expand Down Expand Up @@ -429,6 +435,7 @@ module.exports = function (content) {
' })\n'
output += '})()}\n'
}

// final export
if (options.esModule) {
output += '\nexport default Component.exports\n'
Expand Down Expand Up @@ -461,6 +468,13 @@ module.exports = function (content) {
)
}

function getNamedExport (type, part, index, scoped) {
return (
'export * from ' +
getRequireString(type, part, index, scoped)
)
}

function getRequireString (type, part, index, scoped) {
return loaderUtils.stringifyRequest(
loaderContext,
Expand All @@ -486,6 +500,13 @@ module.exports = function (content) {
)
}

function getNamedExportForImport (type, impt, scoped) {
return (
'export * from ' +
getRequireForImportString(type, impt, scoped)
)
}

function getRequireForImportString (type, impt, scoped) {
return loaderUtils.stringifyRequest(
loaderContext,
Expand Down

0 comments on commit 2e2aa2b

Please sign in to comment.