https://nodejs.org/dist/latest-v12.x/docs/api/modules.html#modules_exports_shortcut
function require(/* ... */) {
const module = { exports: {} };
((module, exports) => {
// Module code here. In this example, define a function.
function someFunc() {}
exports = someFunc;
// At this point, exports is no longer a shortcut to module.exports, and
// this module will still export an empty default object.
module.exports = someFunc;
// At this point, the module will now export someFunc, instead of the
// default object.
})(module, module.exports);
return module.exports;
}
nodejs 的 require
遇到 js 文件的时候会调用内部的 vm
模块,我追源码追到 这里 就看不懂了……