Last active
March 15, 2019 06:55
-
-
Save zzuhan/4bd459bfc657a256bcaf04509678df2b to your computer and use it in GitHub Desktop.
[node-overwrite] nodejs中覆盖 #nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 方法1 | |
var Module = require('module'); | |
const originalLoad = Module._load; | |
// 重写require方法,用来覆盖vscode | |
Module._load = function(request, parent){ | |
if(request == 'vscode') { | |
return require('./mock/vscode'); | |
} | |
return originalLoad.apply(this, [].slice.call(arguments)); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 方法二 | |
var Module = require('module'); | |
var originalRequire = Module.prototype.require; | |
Module.prototype.require = function(){ | |
//do your thing here | |
return originalRequire.apply(this, arguments); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment