Skip to content

Commit

Permalink
fix: compatible with webpack5 externals script
Browse files Browse the repository at this point in the history
  • Loading branch information
fangbinwei committed Dec 20, 2020
1 parent 1c2436a commit 36cc6eb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/codegen/hotReload.js
Expand Up @@ -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}')) {
Expand Down
6 changes: 5 additions & 1 deletion lib/index.js
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions test/core.spec.js
Expand Up @@ -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',
Expand Down

0 comments on commit 36cc6eb

Please sign in to comment.