diff --git a/lib/codegen/hotReload.js b/lib/codegen/hotReload.js index a1315a89d..b37a04982 100644 --- a/lib/codegen/hotReload.js +++ b/lib/codegen/hotReload.js @@ -16,7 +16,7 @@ exports.genHotReloadCode = (id, functional, templateRequest) => { /* hot reload */ if (module.hot) { var api = require(${hotReloadAPIPath}) - api.install(require('vue')) + api.install(Vue) if (api.compatible) { module.hot.accept() if (!api.isRecorded('${id}')) { diff --git a/lib/index.js b/lib/index.js index 7760df47b..e2a27b024 100644 --- a/lib/index.js +++ b/lib/index.js @@ -176,7 +176,11 @@ var component = normalizer( } if (needsHotReload) { - code += `\n` + genHotReloadCode(id, hasFunctional, templateRequest) + code = [ + `import Vue from 'vue'`, + code, + genHotReloadCode(id, hasFunctional, templateRequest) + ].join('\n') } // Expose filename. This is used by the devtools and Vue runtime warnings. diff --git a/test/core.spec.js b/test/core.spec.js index 84a5af1d5..da3526033 100644 --- a/test/core.spec.js +++ b/test/core.spec.js @@ -28,6 +28,20 @@ test('basic', done => { }) }) +test('hot reload code run', done => { + mockBundleAndRun({ + entry: 'basic.vue', + plugins: [ + // bundle with hot-reload code + new (require('webpack').HotModuleReplacementPlugin)() + ] + }, ({ jsdomError }) => { + // run code generated by 'genHotReloadCode' without error + expect(jsdomError).toBeUndefined() + done() + }) +}) + test('pre-processors', done => { mockBundleAndRun({ entry: 'pre.vue',