热重载需要在停机后清空lib以下目录的缓存,以便之后重新require导入

This commit is contained in:
pqcqaq 2024-11-29 23:30:48 +08:00
parent 9acec82bd6
commit cf209f37c2
1 changed files with 6 additions and 0 deletions

View File

@ -87,6 +87,12 @@ const restart = async () => {
if (shutdown) {
await shutdown();
}
// 清空lib以下目录的缓存
Object.keys(require.cache).forEach(function (key) {
if (key.includes('lib')) {
delete require.cache[key];
}
});
const pwd = process.cwd();
const simpleConnector = require('../lib/config/connector').default;
console.warn('----> Starting service......');