I have a project written in CoffeeScript that uses AngularJS. My vendor dependancies are installed using Bower and my file structure is like this:
- assets
- js
- app
- model
- *.coffee
- factory
- *.coffee
...
- app.coffee
- config.coffee
- routes.cofeee
- vendor
- angular
- lodash
...
- dist
What I’m trying to do is the following:
- I’m trying to work out how I can use RequireJS’s
r.jsto optimise my app files so that I essentially get a concatenated file all ordered nice (so vendor dependancies, my config and routes, and they my app files). - Integrate this into my Grunt file.
I’ve tried using the r.js optimiser but maybe I’ve being too silly as all it seems to do is copy my app files (minus the vendor dependancies) into the dist folder; it does, however, manage to optimise the coffee generated js files.
Has anyone got any experience with this?
I figured it out:
r.jsworks by reading yourmainConfigFileand any modules you name within your configuration, the important note here is thatr.jsonly looks at the firstrequire/definewithin your named modules and goes off to seek them; so, for example, I had one named module calledapp:The problem here was that
r.jsnever got past the firstrequirestatement and thus the concatenation wasn’t working. When I changed this to, say (myapp.coffee):And my
bootstrap.coffee:This meant that I only needed to define
angularandbootstrapin myr.jsconfiguration asincludesand thenr.jswould do the rest, like so:And now it all works fine! ~~It’s a shame that I have to tell
r.jsto includerequirejsthough, maybe I’ve done something silly there?~~Blimey, I’m such a dingus!
So in my HTML I was loading my concatenated script as:
When really it should be loaded like this:
D’oh!