[英]RequireJS with CommonJS modules
Using RequireJS with CommonJS modules, what happens when I do this:使用 RequireJS 和 CommonJS 模块,当我这样做时会发生什么:
define(function(require, exports, module) {
//Put traditional CommonJS module content here
var simpleCommonJSModule = require('simple-commonjs-module');
module.exports = new String('foo');
return {
//return empty object along with using module.exports
}
});
if I return something, I assume the module.exports will be ignored?如果我返回一些东西,我假设 module.exports 将被忽略? Or is it the other way around?
或者是周围的其他方式?
Yes, if you return something module.exports will ignored.是的,如果你返回一些东西 module.exports 将被忽略。
Here's a snippet from the original documentation.这是原始文档中的一个片段。
define(function(require, exports, module) {
var a = require('a'),
b = require('b');
//Return the module value
return function () {};
}
);
If you want to use the exports
CJS style here's you do it如果你想使用
exports
CJS风格,你可以这样做
define(function(require, exports, module) {
exports.foo = function () {
return a.bar();
};
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.