Skip to content

Commit

Permalink
fix(plugin-vue): respect hmr: false server config, fix #2790 (#2797)
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqunjiang authored Mar 31, 2021
1 parent b4bbc67 commit 27e0c3f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/plugin-vue/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ export async function transformMain(
output.push('export default _sfc_main')

// HMR
if (devServer && !ssr && !isProduction) {
if (
devServer &&
devServer.config.server.hmr !== false &&
!ssr &&
!isProduction
) {
output.push(`_sfc_main.__hmrId = ${JSON.stringify(descriptor.id)}`)
output.push(
`typeof __VUE_HMR_RUNTIME__ !== 'undefined' && ` +
Expand Down
7 changes: 6 additions & 1 deletion packages/plugin-vue/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export function transformTemplateAsModule(
const result = compile(code, descriptor, options, pluginContext, ssr)

let returnCode = result.code
if (options.devServer && !ssr && !options.isProduction) {
if (
options.devServer &&
options.devServer.config.server.hmr !== false &&
!ssr &&
!options.isProduction
) {
returnCode += `\nimport.meta.hot.accept(({ render }) => {
__VUE_HMR_RUNTIME__.rerender(${JSON.stringify(descriptor.id)}, render)
})`
Expand Down

0 comments on commit 27e0c3f

Please sign in to comment.