Blog >

Minifying AngularJS code created from Yeoman

I recently ran in to a problem when minifying AngularJS code created by the very handy tool Yeoman, in that any dependencies injected in to the code (eg. in controllers, services, directives) etc.  stopped working because the names of the dependencies in the function arguments were minifed.

This is relatively well documented in the AngularJS documentation and questions on StackOverflow (eg. here), however, it was still unclear to me how to implement the annotations in Yeoman created controllers.

I finally deduced the required syntax myself, as follows:

app.controller('MyCtrl', ['$scope', '$window', function ($scope, $window) {
  // code goes here

Whatever dependencies you need can be appended as comma delimited strings before ‘function’, to match the function arguments.

Thought this might help someone else.