直接从另一个 CommonJS 模块导出

Exporting directly from another CommonJS module

我正在使用 CommonJS 和 Browserify,创建一个模块只是为了联合其他模块的导出有什么问题吗?例如:

var submodule1 = require('sub-module-1');
var submodule2 = require('sub-module-2');

module.exports = {
  widget1: submodule1.widget1,
  widget2: submodule2.widget2,
  widget3: submodule2.widget3,
};

没有。这没什么"wrong"。您可以自行决定如何最好地模块化和打包您的代码,以便它对您、您的同事和其他开发人员最有意义。