Although this excellent article on building large Apps with AngularJS http://briantford.com/blog/huuuuuge-angular-apps.html states “I have never seen any instance where requireJS was beneficial in practice” I find this hard to believe with a large dynamic web application where certain modules may never get invoked or be required. Why download a bunch of code and delay application start-up if you’re going to download a ton of code the end user will never use?
The comment also appears to contradict some good material in the O’Reilly book on AngularJS by Brad Green ad Shyam Seshadri who spend quite a few pages of their 200 page book on AngularJS covering the use of requireJS with Angular and using requireJS to bootstrap Angular.
Taking the “RequireJS with AngularJS” approach has however caused a few issues around use of Batarang (now working again, although to be honest I’m not sure how/why since we’d originally assumed this was down to not having ng-app in our HTML markup because of the require bootstrap method of loading Angular)
However we still have an outstanding issue we have not been able to solve to do with a dependency chain for AngularUI seemingly being ignored. We have used a RequireJS shim command (below) to state that AngularUI has a dependency on Angular, but we’re geting an error “Uncaught ReferenceError: Angular is undefined” from the AngularUI code – it’s as if the RequireJS dependency is being ignored.
require({
paths: {
angularui: "vendor/angular-ui"
},
shim: {
angularui: {
deps: ["vendor/angular"]
},
"vendor/angular": {
exports: "angular"
}
}
This dependency problem aside (any advice on what the problem might be appreciated), but in the meantime I’m interested to hear whether others think mixing and matching AngularJS and RequireJS is something that should be avoided.