I realized: r.js works by reading your mainConfigFile and any modules that you name in your configuration, it is important to note that r.js looks only at the first require / define in your named modules and goes to look for them; therefore, for example, I had one module named app :
require ['config'], (cfg) -> require ['angular'], (A) -> A.module cfg.ngApp, [] require ['routes'], () -> require [ 'factory/a-factory', 'service/a-service', 'controller/a-controller' ], () -> A.bootstrap document, [cfg.ngApp]
The problem was that r.js never passed the first require statement, and so concatenation didn't work. When I changed this, say (my app.coffee ):
require ['config'], (cfg) -> require ['angular'], (A) -> A.module cfg.ngApp, [] require ['bootstrap'], (bootstrap) -> bootstrap()
And my bootstrap.coffee :
define [ 'config', 'angular', 'routes', 'factory/a-factory', 'service/a-service', 'controller/a-controller' ], (cfg, A, routes) -> class Bootstrap constructor: () -> routes() A.bootstrap document, [cfg.ngApp]
This meant that I needed to define angular and bootstrap in my r.js configuration as includes , and then r.js would do the rest, for example:
baseUrl: 'assets/js/app', mainConfigFile: 'assets/js/app/config.js', name: 'app', include: [ '../vendor/requirejs/require', 'bootstrap' ], out: 'assets/js/dist/app.js'
And now everything works fine! ~~ Shame that I should tell r.js to include requirejs , although maybe I did something stupid there? ~~
Blimey, I'm such a false emblem!
So, in my HTML, I loaded my concatenated script as:
<script src="assets/js/dist/app.js"></script>
When it really should be loaded as follows:
<script src="assets/js/vendor/requirejs/require.js" data-main="assets/js/dist/app"></script>
D'o!