From ed4fe00ff8f3586132f66f59fcaeeaefb1f998e0 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 31 Mar 2021 14:19:13 +0800 Subject: [PATCH] fix(plugin-vue): respect `hmr: false` server config Fixes #2790 --- packages/plugin-vue/src/main.ts | 7 ++++++- packages/plugin-vue/src/template.ts | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index 713449a3a7e555..1d2f896e79cb2a 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -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' && ` + diff --git a/packages/plugin-vue/src/template.ts b/packages/plugin-vue/src/template.ts index f42a8a9dae62de..e84010d4126edd 100644 --- a/packages/plugin-vue/src/template.ts +++ b/packages/plugin-vue/src/template.ts @@ -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) })`