Skip to content

Commit 6427984

Browse files
committed
handle older versions of Vue
1 parent 0908484 commit 6427984

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

lib/hot-shim.js renamed to lib/hot-reload-api.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,22 @@ var shimmed = false
99
exports.install = function (Vue) {
1010
if (shimmed) return
1111
shimmed = true
12-
console.log('[HMR] Vue component hot reload shim applied.')
12+
13+
exports.compatible = !!Vue.internalDirectives
14+
if (!exports.compatible) {
15+
console.warn(
16+
'[HMR] vue-loader hot reload is only compatible with ' +
17+
'Vue.js 1.0.0+.'
18+
)
19+
return
20+
}
21+
22+
// create global hot reload map
1323
var map = Vue.config._hotComponents = Object.create(null)
24+
// check compatibility
1425
var componentDir = Vue.internalDirectives.component
15-
26+
27+
// shim the component directive
1628
var set = componentDir.setComponent
1729
componentDir.setComponent = function (id, cb) {
1830
var prevComponent = this.Component
@@ -50,6 +62,8 @@ exports.install = function (Vue) {
5062
}
5163
unbind.call(this)
5264
}
65+
66+
console.log('[HMR] Vue component hot reload shim applied.')
5367
}
5468

5569
/**

lib/loader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ module.exports = function (content) {
137137
// shim the component directive so that it
138138
// registers the instances
139139
'var Vue = require("vue")\n' +
140-
'var shim = require("' + require.resolve('./hot-shim') + '")\n' +
141-
'shim.install(Vue)\n' +
140+
'var hotAPI = require("' + require.resolve('./hot-reload-api') + '")\n' +
141+
'hotAPI.install(Vue)\n' +
142+
'if (!hotAPI.compatible) return\n' +
142143
'var map = Vue.config._hotComponents\n' +
143144
'var id = module.exports.hotID = ' + (scriptString || templateString) + '\n' +
144145
'module.hot.accept(' + JSON.stringify(accepted) + ', function () {\n' +
@@ -149,7 +150,7 @@ module.exports = function (content) {
149150
// reset linker
150151
'Ctor.linker = null\n' +
151152
// reload directive instances
152-
'map[id].instances.forEach(shim.update)\n' +
153+
'map[id].instances.forEach(hotAPI.update)\n' +
153154
// re-enable transitions
154155
'})\n' +
155156
'})()\n' +

0 commit comments

Comments
 (0)