Skip to content

Commit 747f5d0

Browse files
committed
feat: package.json hmr for vite
1 parent d145467 commit 747f5d0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/core/index.ts

+21
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ export const UnpluginInfo = createUnplugin<Options | undefined>((option) => {
9999
.map(([key, value]) => `export const ${key} = ${JSON.stringify(value, null, 2)};`)
100100
.join('\n');
101101
}
102+
},
103+
vite: {
104+
handleHotUpdate({ file, server }) {
105+
// HMR: package.json
106+
if (file === normalizePath(path.resolve(root, 'package.json'))) {
107+
const module = server.moduleGraph.getModuleById('\0' + ModuleName.BuildPackage);
108+
if (module) {
109+
// Invalidate module for reloading
110+
server.moduleGraph.invalidateModule(module);
111+
112+
// Reload client
113+
server.ws.send({
114+
type: 'full-reload'
115+
});
116+
}
117+
}
118+
}
102119
}
103120
};
104121
});
122+
123+
function normalizePath(filename: string) {
124+
return filename.split(path.win32.sep).join(path.posix.sep);
125+
}

0 commit comments

Comments
 (0)