Skip to content

Commit

Permalink
feat: package.json hmr for vite
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Jan 26, 2024
1 parent d145467 commit 747f5d0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ export const UnpluginInfo = createUnplugin<Options | undefined>((option) => {
.map(([key, value]) => `export const ${key} = ${JSON.stringify(value, null, 2)};`)
.join('\n');
}
},
vite: {
handleHotUpdate({ file, server }) {
// HMR: package.json
if (file === normalizePath(path.resolve(root, 'package.json'))) {
const module = server.moduleGraph.getModuleById('\0' + ModuleName.BuildPackage);
if (module) {
// Invalidate module for reloading
server.moduleGraph.invalidateModule(module);

// Reload client
server.ws.send({
type: 'full-reload'
});
}
}
}
}
};
});

function normalizePath(filename: string) {
return filename.split(path.win32.sep).join(path.posix.sep);
}

0 comments on commit 747f5d0

Please sign in to comment.