@@ -122,6 +122,7 @@ module.exports = function (content) {
122122 process . env . NODE_ENV !== 'production' &&
123123 ( parts . script . length || parts . template . length )
124124 ) {
125+ var hotReloadAPIPath = require . resolve ( './hot-reload-api' ) . replace ( / \\ / g, "\\\\" )
125126 var scriptString = parts . script . length ? getRequireString ( 'script' , parts . script [ 0 ] , 0 ) : ''
126127 var templateString = parts . template . length ? getRequireString ( 'template' , parts . template [ 0 ] , 0 , hasLocalStyles ) : ''
127128 var accepted = [ ]
@@ -137,16 +138,25 @@ module.exports = function (content) {
137138 // shim the component directive so that it
138139 // registers the instances
139140 'var Vue = require("vue")\n' +
140- 'var hotAPI = require("' + require . resolve ( './hot-reload-api' ) + '")\n' +
141+ 'var hotAPI = require("' + hotReloadAPIPath + '")\n' +
141142 'hotAPI.install(Vue)\n' +
142143 'if (!hotAPI.compatible) return\n' +
143144 'var map = Vue.config._hotComponents\n' +
144145 'var id = module.exports.hotID = ' + ( scriptString || templateString ) + '\n' +
146+ // store the record
147+ 'if (typeof module.exports.el !== "string" && typeof module.exports.data !== "object") {\n' +
148+ 'map[id] = { Ctor: Vue.extend(module.exports), instances: [] }\n' +
149+ '}\n' +
145150 'module.hot.accept(' + JSON . stringify ( accepted ) + ', function () {\n' +
151+ 'if (!map[id]) {\n' +
152+ 'throw new Error("Root or manually-mounted instance modified. Full reload is required.")\n' +
153+ '}\n' +
146154 'var Ctor = map[id].Ctor\n' +
147155 // overwrite existing constructor's options
148156 ( scriptString ? 'Ctor.options = Vue.util.mergeOptions(Vue.options, require(' + scriptString + '))\n' : '' ) +
149157 ( templateString ? 'Ctor.options.template = require(' + templateString + ')\n' : '' ) +
158+ // handle recursive names
159+ 'if (Ctor.options.name) Ctor.options.components[Ctor.options.name] = Ctor\n' +
150160 // reset linker
151161 'Ctor.linker = null\n' +
152162 // reload directive instances
0 commit comments