The two solutions below require modifications to the source of foo
. Since you can control it, they are both viable:
(Quick and dirty) Hardcode the module name in the define call:
// foo.js if (typeof define === 'function' && define.amd) { return define("foo", dependencies, module); }
(Cleaner) See the code of Knockout.js at the beginning. I am using it in a project and it seems to compile good with r.js. I tried a simple project setup like yours, and it works; so you have to replace the AMD compatibility code as follows:
(function(factory) { // Support three module loading scenarios if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { // [1] CommonJS/Node.js var target = module['exports'] || exports; // module.exports is for Node.js var hex_sha256 = require("sha256"); factory(target, hex_sha256); } else if (typeof define === 'function' && define['amd']) { // [2] AMD anonymous module define(['exports','sha256'], factory); } else { // [3] No module loader (plain <script> tag) - put directly in global namespace factory(window['foo'] = {}, hex_sha256); } }(function(exports, sha256){ // same foo }));
I do not know what magic happens inside r.js and this works...