Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Requirejs and Commonjs crossmodule standard boilerplate
(typeof define==="function"?define:function(f){var r=f(require,exports,module);module.exports=(r!==void 0?r:module.exports);})(function(require,exports,module){
return 27;
})
(typeof define==="function"?define:function(f){var r=f(require,exports,module);module.exports=(r!==void 0?r:module.exports);})(function(require,exports,module){
module.exports = 27;
})
console.log(require('moduleA')); // 27
define(['moduleA'], function(moduleA){
console.log(moduleA); // 27
})
define(function(require, exports, module){
console.log(require('moduleA')); // 27
})
@totty90
Owner

Module we are making:

  • moduleA.js: returning the module;
  • moduleB.js: setting the module.exports variable;

Both way works the same. But remember to don't do both: you should not return a module and also set the module.exports variable;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.