Skip to content

Commit bacc6a9

Browse files
committed
fix(hmr): fix hmr regression
1 parent c9e61c1 commit bacc6a9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/hotReload.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ export function genHotReloadCode(
77
return `
88
/* hot reload */
99
if (module.hot) {
10-
script.__hmrId = "${id}"
10+
__exports__.__hmrId = "${id}"
1111
const api = __VUE_HMR_RUNTIME__
1212
module.hot.accept()
13-
if (!api.createRecord('${id}', script)) {
14-
api.reload('${id}', script)
13+
if (!api.createRecord('${id}', __exports__)) {
14+
console.log('reload')
15+
api.reload('${id}', __exports__)
1516
}
1617
${templateRequest ? genTemplateHotReloadCode(id, templateRequest) : ''}
1718
}
@@ -21,6 +22,7 @@ if (module.hot) {
2122
function genTemplateHotReloadCode(id: string, request: string) {
2223
return `
2324
module.hot.accept(${request}, () => {
25+
console.log('re-render')
2426
api.rerender('${id}', render)
2527
})
2628
`

src/index.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,6 @@ export default function loader(
245245
propsToAttach.push([`__scopeId`, `"data-v-${id}"`])
246246
}
247247

248-
if (needsHotReload) {
249-
code += genHotReloadCode(id, templateRequest)
250-
}
251-
252248
// Expose filename. This is used by the devtools and Vue runtime warnings.
253249
if (!isProduction) {
254250
// Expose the file's full path in development, so that it can be opened
@@ -286,13 +282,19 @@ export default function loader(
286282

287283
// finalize
288284
if (!propsToAttach.length) {
289-
code += `\n\nexport default script`
285+
code += `\n\nconst __exports__ = script;`
290286
} else {
291287
code += `\n\nimport exportComponent from ${exportHelperPath}`
292-
code += `\nexport default /*#__PURE__*/exportComponent(script, [${propsToAttach
288+
code += `\nconst __exports__ = /*#__PURE__*/exportComponent(script, [${propsToAttach
293289
.map(([key, val]) => `['${key}',${val}]`)
294290
.join(',')}])`
295291
}
292+
293+
if (needsHotReload) {
294+
code += genHotReloadCode(id, templateRequest)
295+
}
296+
297+
code += `\n\nexport default __exports__`
296298
return code
297299
}
298300

0 commit comments

Comments
 (0)