Skip to content
Create a gist now

Instantly share code, notes, and snippets.

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
totty90 commented Jul 11, 2014

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.