DEMO
文件目录结构
plugin.js
// /CommonJS规范
// var exports = module.exports;
exports.test = function () {
console.log("This is a plugin");
}
req1.js
const plugin = require("./plugin");
require("./req2")(plugin); // 等于是执行module.exports
req2.js
module.exports = plugin => {
// Do something with plugin
plugin.test();
}
运行req1.js