nodejs如何实现模块热更新require自动更新?
网友回复
可以实现,主要是通过清除clear module的cache来实现,代码如下
var fs = require("fs"); //文件系统模块
//删除文件的cache缓存
function cleanCache(modulePath) {
var module = require.cache[modulePath];
if (!module) {
return;
}
if (module.parent) {
module.parent.children.splice(module.parent.children.indexOf(module), 1);
}
require.cache[modulePath] = null;
}
//监...点击查看剩余70%


