Skip to content

Commit

Permalink
improve hot-reload support for functional components
Browse files Browse the repository at this point in the history
and bump vue-hot-reload-api version
  • Loading branch information
yyx990803 committed Oct 11, 2017
1 parent f5b944b commit c7b5376
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
3 changes: 3 additions & 0 deletions lib/component-normalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ module.exports = function normalizeComponent (
? [].concat(existing, hook)
: [hook]
} else {
// for template-only hot-reload because in that case the render fn doesn't
// go through the normalizer
options._injectStyles = hook
// register for functioal component in vue file
options.render = function renderWithStyleInjection (h, context) {
hook.call(context)
Expand Down
12 changes: 5 additions & 7 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,17 +386,13 @@ module.exports = function (content) {
output +=
'\n/* hot reload */\n' +
'if (module.hot) {(function () {\n' +
' var hotAPI = require("' +
hotReloadAPIPath +
'")\n' +
' var hotAPI = require("' + hotReloadAPIPath + '")\n' +
' hotAPI.install(require("vue"), false)\n' +
' if (!hotAPI.compatible) return\n' +
' module.hot.accept()\n' +
' if (!module.hot.data) {\n' +
// initial insert
' hotAPI.createRecord("' +
moduleId +
'", Component.options)\n' +
' hotAPI.createRecord("' + moduleId + '", Component.options)\n' +
' } else {\n'
// update
if (cssModules) {
Expand All @@ -406,7 +402,9 @@ module.exports = function (content) {
' }\n'
}
output +=
' hotAPI.reload("' + moduleId + '", Component.options)\n' + ' }\n'
` hotAPI.${
functionalTemplate ? 'rerender' : 'reload'
}("${moduleId}", Component.options)\n' + ' }\n`
// dispose
output +=
' module.hot.dispose(function (data) {\n' +
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"prettier": "^1.7.0",
"resolve": "^1.4.0",
"source-map": "^0.6.1",
"vue-hot-reload-api": "^2.1.0",
"vue-hot-reload-api": "^2.2.0",
"vue-style-loader": "^3.0.0",
"vue-template-es2015-compiler": "^1.6.0"
},
Expand Down

0 comments on commit c7b5376

Please sign in to comment.