Skip to content

Commit c7b5376

Browse files
committed
improve hot-reload support for functional components
and bump vue-hot-reload-api version
1 parent f5b944b commit c7b5376

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

lib/component-normalizer.js

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ module.exports = function normalizeComponent (
8484
? [].concat(existing, hook)
8585
: [hook]
8686
} else {
87+
// for template-only hot-reload because in that case the render fn doesn't
88+
// go through the normalizer
89+
options._injectStyles = hook
8790
// register for functioal component in vue file
8891
options.render = function renderWithStyleInjection (h, context) {
8992
hook.call(context)

lib/loader.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -386,17 +386,13 @@ module.exports = function (content) {
386386
output +=
387387
'\n/* hot reload */\n' +
388388
'if (module.hot) {(function () {\n' +
389-
' var hotAPI = require("' +
390-
hotReloadAPIPath +
391-
'")\n' +
389+
' var hotAPI = require("' + hotReloadAPIPath + '")\n' +
392390
' hotAPI.install(require("vue"), false)\n' +
393391
' if (!hotAPI.compatible) return\n' +
394392
' module.hot.accept()\n' +
395393
' if (!module.hot.data) {\n' +
396394
// initial insert
397-
' hotAPI.createRecord("' +
398-
moduleId +
399-
'", Component.options)\n' +
395+
' hotAPI.createRecord("' + moduleId + '", Component.options)\n' +
400396
' } else {\n'
401397
// update
402398
if (cssModules) {
@@ -406,7 +402,9 @@ module.exports = function (content) {
406402
' }\n'
407403
}
408404
output +=
409-
' hotAPI.reload("' + moduleId + '", Component.options)\n' + ' }\n'
405+
` hotAPI.${
406+
functionalTemplate ? 'rerender' : 'reload'
407+
}("${moduleId}", Component.options)\n' + ' }\n`
410408
// dispose
411409
output +=
412410
' module.hot.dispose(function (data) {\n' +

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"prettier": "^1.7.0",
5252
"resolve": "^1.4.0",
5353
"source-map": "^0.6.1",
54-
"vue-hot-reload-api": "^2.1.0",
54+
"vue-hot-reload-api": "^2.2.0",
5555
"vue-style-loader": "^3.0.0",
5656
"vue-template-es2015-compiler": "^1.6.0"
5757
},

0 commit comments

Comments
 (0)