Skip to content

Commit

Permalink
feat: basic hot reload
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Mar 19, 2018
1 parent 878f1b8 commit f418bd9
Show file tree
Hide file tree
Showing 4 changed files with 695 additions and 19 deletions.
20 changes: 20 additions & 0 deletions lib/hotReload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const hotReloadAPIPath = require.resolve('vue-hot-reload-api')

module.exports = function genHotReloadCode (id, functional) {
// TODO handle CSSModules and style injection disposal
return `
/* hot reload */
if (module.hot) {
var api = require('${hotReloadAPIPath}')
api.install(require('vue'))
if (api.compatible) {
module.hot.accept()
if (!module.hot.data) {
api.createRecord('${id}', component.options)
} else {
api.${functional ? `rerender` : `reload`}('${id}', component.options)
}
}
}
`.trim()
}
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const qs = require('querystring')
const loaderUtils = require('loader-utils')
const selectBlock = require('./selector')
const plugin = require('./plugin')
const genHotReloadCode = require('./hotReload')
const componentNormalizerPath = require.resolve('./runtime/componentNormalizer')

module.exports = function (source) {
Expand Down Expand Up @@ -119,7 +120,7 @@ var component = normalizer(
${isServer ? JSON.stringify(hash(request)) : `null`}
${incomingQuery.shadow ? `,true` : ``}
)
`.trim()
`.trim()

if (descriptor.customBlocks && descriptor.customBlocks.length) {
// TODO custom blocks
Expand All @@ -130,7 +131,7 @@ var component = normalizer(
}

if (needsHotReload) {
// TODO hot reload
code += genHotReloadCode(id, hasFunctional)
}

code += `\nexport default component.exports`
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"vue-template-compiler": "^2.5.16",
"webpack": "^4.1.0",
"webpack-cli": "^2.0.10",
"webpack-dev-server": "^3.1.1",
"webpack-merge": "^4.1.2",
"yorkie": "^1.0.3"
},
Expand Down

0 comments on commit f418bd9

Please sign in to comment.