title: How can I load multiple optimized requirejs modules dynamically in a production env?
body: <p>I've started to play with require js on a dummy project. I now want to use the r.js script to build my project for production. </p>
  
  <p>The context is this:</p>
  
  <ul>
  <li><p>Main file called start.js is: </p>
  
  <pre><code>require([/* some stuff */], function (){ /* app logic */ });
  </code></pre>
  
  <p>which has an if that decides what I should require based on some condition.</p></li>
  <li><p>The required files are either ModuleA or ModuleB</p></li>
  <li><p>Both ModuleA and ModuleB have dependencies. </p>
  
  <pre><code>define([/*some deps*/], function(dep1, dep2...) { 
      /* app logic */ 
      return { /* interface */
  }
  </code></pre></li>
  <li><p>Everything works fine in development mode, before optimization and module concatenation.</p></li>
  <li><p>When building with r.js I specify as module targets the following : 
      modules : [ { name : "start" }, { name : "ModuleA" }, { name : "ModuleB" } ]</p></li>
  </ul>
  
  <p>The problem is that my ModuleA becomes : </p>
  
  <pre><code> define(dep1 ..);
   define(dep2 ..);
   define(ModuleA ..);
  </code></pre>
  
  <p>But nothings loads from ModuleA. The code from ModeulA in development loads and executes, the code after building loads but does not run.</p>
  
  <p>How could I fix this problem?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p><a href="http://pastebin.com/p1xUcY0A" rel="nofollow">http://pastebin.com/p1xUcY0A</a> --> start.js</p>
  
  <p><a href="http://pastebin.com/dXa6PtpX" rel="nofollow">http://pastebin.com/dXa6PtpX</a> --> ModuleA js-animation.js</p>
  
  <p><a href="http://pastebin.com/xcCvhLrT" rel="nofollow">http://pastebin.com/xcCvhLrT</a> --> ModuleB css-animation.js no deps.</p>
  
  <p><a href="http://pastebin.com/j51V5kMt" rel="nofollow">http://pastebin.com/j51V5kMt</a> --> The r.js config file used when running the optimizer.</p>
  
  <p><a href="http://pastebin.com/UVkWjwe9" rel="nofollow">http://pastebin.com/UVkWjwe9</a> --> How the js-animation.js looks after running r.js. This is the file that has problems. I don't get the js-animation module from this file. The require does not return my js-animation object. </p>
  
  <p>Edit:</p>
  
  <p>After removing the .js at the end of the module definitions and in from start js, the optimized   start.js is <a href="http://pastebin.com/LfaLkJaT" rel="nofollow">http://pastebin.com/LfaLkJaT</a> and the js-animations module is <a href="http://pastebin.com/qwnpkCC6" rel="nofollow">http://pastebin.com/qwnpkCC6</a>. In chrome, I get this error in my console <a href="http://pastebin.com/Hq7HGcmm" rel="nofollow">http://pastebin.com/Hq7HGcmm</a></p>