Skip to content

Commit 625b9bb

Browse files
committed
feat: update to support named render function export
1 parent aa5530d commit 625b9bb

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/index.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,16 @@ const loader: webpack.loader.Loader = function(source: string) {
7676
const isServer = target === 'node'
7777
const isProduction = mode === 'production'
7878

79-
let descriptor
80-
try {
81-
descriptor = parse(source, {
82-
filename: resourcePath,
83-
sourceMap
79+
const { descriptor, errors } = parse(source, {
80+
filename: resourcePath,
81+
sourceMap
82+
})
83+
84+
if (errors.length) {
85+
errors.forEach(err => {
86+
formatError(err, source, resourcePath)
87+
loaderContext.emitError(err)
8488
})
85-
} catch (e) {
86-
formatError(e, source, resourcePath)
87-
loaderContext.emitError(e)
8889
return ``
8990
}
9091

@@ -125,7 +126,7 @@ const loader: webpack.loader.Loader = function(source: string) {
125126
const attrsQuery = attrsToQuery(descriptor.template.attrs)
126127
const query = `?vue&type=template${idQuery}${scopedQuery}${attrsQuery}${resourceQuery}`
127128
templateRequest = stringifyRequest(src + query)
128-
templateImport = `import render from ${templateRequest}`
129+
templateImport = `import { render } from ${templateRequest}`
129130
}
130131

131132
// script

src/pitcher.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,22 @@ pitcher.pitch = function() {
8383

8484
// Rewrite request. Technically this should only be done when we have deduped
8585
// loaders. But somehow this is required for block source maps to work.
86-
return genProxyModule(loaders, context)
86+
return genProxyModule(loaders, context, query.type !== 'template')
8787
}
8888

8989
function genProxyModule(
9090
loaders: Loader[],
91-
context: webpack.loader.LoaderContext
91+
context: webpack.loader.LoaderContext,
92+
exportDefault = true
9293
) {
9394
const request = genRequest(loaders, context)
9495
// return a proxy module which simply re-exports everything from the
95-
// actual request.
96-
return `export { default } from ${request}; export * from ${request}`
96+
// actual request. Note for template blocks the compiled module has no
97+
// default export.
98+
return (
99+
(exportDefault ? `export { default } from ${request}; ` : ``) +
100+
`export * from ${request}`
101+
)
97102
}
98103

99104
function genRequest(loaders: Loader[], context: webpack.loader.LoaderContext) {

0 commit comments

Comments
 (0)