Override the require function

后端 未结 4 1162
故里飘歌
故里飘歌 2020-12-08 10:45

Is it possible to override the global require function, affecting it at process level?

From what I know, the require

4条回答
  •  星月不相逢
    2020-12-08 11:13

    var Module = require('module');
    var originalRequire = Module.prototype.require;
    
    Module.prototype.require = function(){
      //do your thing here
      return originalRequire.apply(this, arguments);
    };
    

提交回复
热议问题