Skip to content

Commit

Permalink
use simpler hot-reload mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 6, 2015
1 parent 0192d64 commit 95cf0b7
Showing 1 changed file with 14 additions and 31 deletions.
45 changes: 14 additions & 31 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,38 +177,21 @@ module.exports = function (content) {
process.env.NODE_ENV !== 'production' &&
(parts.script.length || parts.template.length)
) {
var scriptString = parts.script.length ? getRequireString('script', parts.script[0], 0) : ''
var templateString = template
? template.src
? getRequireForImportString('template', template, hasLocalStyles)
: getRequireString('template', template, 0, hasLocalStyles)
: ''
var accepted = []
if (scriptString) {
accepted.push(scriptString.slice(1, -1))
}
if (templateString) {
accepted.push(templateString.slice(1, -1))
}
output +=
'if (module.hot) {\n' +
'(function () {\n' +
// shim the component directive so that it
// registers the instances
'var hotAPI = require("vue-hot-reload-api")\n' +
'hotAPI.install(require("vue"))\n' +
'if (!hotAPI.compatible) return\n' +
'var id = ' + (scriptString || templateString) + '\n' +
// create the record
'hotAPI.createRecord(id, module.exports)\n' +
'module.hot.accept(' + JSON.stringify(accepted) + ', function () {\n' +
'var newOptions = ' + (scriptString ? 'require(' + scriptString + ')\n' : 'null\n') +
'if (newOptions && newOptions.__esModule) newOptions = newOptions.default\n' +
'var newTemplate = ' + (templateString ? 'require(' + templateString + ')\n' : 'null\n') +
'hotAPI.update(id, newOptions, newTemplate)\n' +
'})\n' +
'})()\n' +
'}'
'if (module.hot) {(function () {' +
' module.hot.accept()\n' +
' var hotAPI = require("vue-hot-reload-api")\n' +
' hotAPI.install(require("vue"), true)\n' +
' if (!hotAPI.compatible) return\n' +
' var id = ' + JSON.stringify(filePath) + '\n' +
' if (!module.hot.data) {\n' +
// initial insert
' hotAPI.createRecord(id, module.exports)\n' +
' } else {\n' +
// update
' hotAPI.update(id, module.exports, (typeof module.exports === "function" ? module.exports.options : module.exports).template)\n' +
' }\n' +
'})()}'
}

// done
Expand Down

0 comments on commit 95cf0b7

Please sign in to comment.