Skip to content

Commit

Permalink
fix(hmr): fix hmr regression
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Sep 22, 2021
1 parent c9e61c1 commit bacc6a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/hotReload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ export function genHotReloadCode(
return `
/* hot reload */
if (module.hot) {
script.__hmrId = "${id}"
__exports__.__hmrId = "${id}"
const api = __VUE_HMR_RUNTIME__
module.hot.accept()
if (!api.createRecord('${id}', script)) {
api.reload('${id}', script)
if (!api.createRecord('${id}', __exports__)) {
console.log('reload')
api.reload('${id}', __exports__)
}
${templateRequest ? genTemplateHotReloadCode(id, templateRequest) : ''}
}
Expand All @@ -21,6 +22,7 @@ if (module.hot) {
function genTemplateHotReloadCode(id: string, request: string) {
return `
module.hot.accept(${request}, () => {
console.log('re-render')
api.rerender('${id}', render)
})
`
Expand Down
14 changes: 8 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ export default function loader(
propsToAttach.push([`__scopeId`, `"data-v-${id}"`])
}

if (needsHotReload) {
code += genHotReloadCode(id, templateRequest)
}

// Expose filename. This is used by the devtools and Vue runtime warnings.
if (!isProduction) {
// Expose the file's full path in development, so that it can be opened
Expand Down Expand Up @@ -286,13 +282,19 @@ export default function loader(

// finalize
if (!propsToAttach.length) {
code += `\n\nexport default script`
code += `\n\nconst __exports__ = script;`
} else {
code += `\n\nimport exportComponent from ${exportHelperPath}`
code += `\nexport default /*#__PURE__*/exportComponent(script, [${propsToAttach
code += `\nconst __exports__ = /*#__PURE__*/exportComponent(script, [${propsToAttach
.map(([key, val]) => `['${key}',${val}]`)
.join(',')}])`
}

if (needsHotReload) {
code += genHotReloadCode(id, templateRequest)
}

code += `\n\nexport default __exports__`
return code
}

Expand Down

0 comments on commit bacc6a9

Please sign in to comment.