Skip to content

Commit 95cf0b7

Browse files
committed
use simpler hot-reload mechanism
1 parent 0192d64 commit 95cf0b7

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

lib/loader.js

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -177,38 +177,21 @@ module.exports = function (content) {
177177
process.env.NODE_ENV !== 'production' &&
178178
(parts.script.length || parts.template.length)
179179
) {
180-
var scriptString = parts.script.length ? getRequireString('script', parts.script[0], 0) : ''
181-
var templateString = template
182-
? template.src
183-
? getRequireForImportString('template', template, hasLocalStyles)
184-
: getRequireString('template', template, 0, hasLocalStyles)
185-
: ''
186-
var accepted = []
187-
if (scriptString) {
188-
accepted.push(scriptString.slice(1, -1))
189-
}
190-
if (templateString) {
191-
accepted.push(templateString.slice(1, -1))
192-
}
193180
output +=
194-
'if (module.hot) {\n' +
195-
'(function () {\n' +
196-
// shim the component directive so that it
197-
// registers the instances
198-
'var hotAPI = require("vue-hot-reload-api")\n' +
199-
'hotAPI.install(require("vue"))\n' +
200-
'if (!hotAPI.compatible) return\n' +
201-
'var id = ' + (scriptString || templateString) + '\n' +
202-
// create the record
203-
'hotAPI.createRecord(id, module.exports)\n' +
204-
'module.hot.accept(' + JSON.stringify(accepted) + ', function () {\n' +
205-
'var newOptions = ' + (scriptString ? 'require(' + scriptString + ')\n' : 'null\n') +
206-
'if (newOptions && newOptions.__esModule) newOptions = newOptions.default\n' +
207-
'var newTemplate = ' + (templateString ? 'require(' + templateString + ')\n' : 'null\n') +
208-
'hotAPI.update(id, newOptions, newTemplate)\n' +
209-
'})\n' +
210-
'})()\n' +
211-
'}'
181+
'if (module.hot) {(function () {' +
182+
' module.hot.accept()\n' +
183+
' var hotAPI = require("vue-hot-reload-api")\n' +
184+
' hotAPI.install(require("vue"), true)\n' +
185+
' if (!hotAPI.compatible) return\n' +
186+
' var id = ' + JSON.stringify(filePath) + '\n' +
187+
' if (!module.hot.data) {\n' +
188+
// initial insert
189+
' hotAPI.createRecord(id, module.exports)\n' +
190+
' } else {\n' +
191+
// update
192+
' hotAPI.update(id, module.exports, (typeof module.exports === "function" ? module.exports.options : module.exports).template)\n' +
193+
' }\n' +
194+
'})()}'
212195
}
213196

214197
// done

0 commit comments

Comments
 (0)