单个导出(exports.test1)、批量导出(module.exports) 使用时一定要注意~
有个exports.default,没记~
// 首先exports相当于一个代理,exports.test1 = 1 等价于 module.exports.test1 = 1
// a.js
exports.test1 = 1;
module.exports = {name:'js file'}; // test1消失了!因为重新赋值了module.exports
// b.js
// 也许你是想这样做
exports.test2 = 2;
module.exports = Object.assign(exports, { name: 'js file' });
// main.js
const { test1 } = require('./a');
const a = require('./a');
console.log(test1, a);
const { test2 } = require('./b');
const b = require('./b');
console.log(test2, b);