@@ -2,7 +2,7 @@ import path from 'node:path'
22import type { SFCBlock , SFCDescriptor } from 'vue/compiler-sfc'
33import type { PluginContext , TransformPluginContext } from 'rollup'
44import type { RawSourceMap } from 'source-map'
5- import { transformWithEsbuild } from 'vite'
5+ import { transformWithEsbuild , normalizePath } from 'vite'
66import {
77 createDescriptor ,
88 getPrevDescriptor ,
@@ -110,12 +110,24 @@ var __component__ = /*#__PURE__*/__normalizer(
110110 ` __VUE_HMR_RUNTIME__.createRecord(${ id } , __component__.options)` ,
111111 `}`
112112 )
113+ output . push (
114+ `import.meta.hot.on('file-changed', ({ file }) => {` ,
115+ ` __VUE_HMR_RUNTIME__.CHANGED_FILE = file` ,
116+ `})` ,
117+ )
113118 // check if the template is the only thing that changed
114119 if (
115120 hasFunctional ||
116121 ( prevDescriptor && isOnlyTemplateChanged ( prevDescriptor , descriptor ) )
117122 ) {
118- output . push ( `export const _rerender_only = true` )
123+ // https://github.com/vitejs/vite-plugin-vue/issues/7
124+ // #7 only consider re-render if the HMR is triggered by the current component,
125+ // otherwise reload. Due to vite will cache the transform result. If the HMR
126+ // is triggered by other files that the current component relies on, a reload
127+ // is required.
128+ output . push (
129+ `export const _rerender_only = __VUE_HMR_RUNTIME__.CHANGED_FILE === ${ JSON . stringify ( normalizePath ( filename ) ) } ` ,
130+ )
119131 }
120132 output . push (
121133 `import.meta.hot.accept(mod => {` ,
0 commit comments