-1

Im pretty new and trying to build a app Its working fine

Now I am trying to minify the files:
Error: Unknown provider: aProvider <- a

uglify: {
        my_target: {
          files: {
            'app/output/output.js': [
                'app/js/angular-ui-router.js',
                'app/js/angular-animate.js',
                'app/js/packery.pkgd.js',
                'app/js/app.js',
                'app/js/services.js',
                'app/js/controllers.js',
                'app/js/directives.js'
            ]
          }
        }
      }

1) How to solve this problem?

2) Some of blog examples suggesting to use grunt-contrib-concat before uglify use - why?

Second question is confusing me

Edit:

After read about ng-annotate They Must be written using the array syntax.

My code strcture like this

var app = angular.module('bigApp', []);

app.controller('mainController', ['$scope', function($scope) {
    $scope.message = 'HOORAY!'; 
}]);

But didnt solve error 'Unknown provider: aProvider <- a'

Hunter
  • 1,515
  • 4
  • 15
  • 25
  • Seriously, google for "angular minification". There are dozens of pages, including in the official documentation, explaining how to make angular code minifiable. Use ng-annotate. – JB Nizet May 02 '16 at 18:43
  • @JBNizet Thanks for you info sharing , I edit my question could you please check – Hunter May 02 '16 at 19:25
  • First of all, I wouldn't minify angular-ui-router and angular-animate: those two provide already minified versions that are tested and work fine, and you should reuse them as is (or by concatenating them with your own minified files). Second: you misread ng-annotate: its whole point is to let you write simple coden without using the ugly array syntax. ngannotate will rewrite your code with this ugly array syntax as part of the build, before the minification. Third, if you still have this problem, and you only minified your code, then it means you're missing an array syntax somewhere. – JB Nizet May 02 '16 at 19:30

1 Answers1

1

The files should be concatenated before you uglify them and the reason why is that uglify will change names of functions, controllers and so on, when you do it like in your example the files will be uglified out of context of the whole application and renamed functions cant be found properly. And to uglify Angularjs properly you should have ng-annotate in grunt as well, unless you already use following notation in controllers/services/factories

need ng-annotate

.controller('myController', function (serviceA, factoryB, filterC){
  //something fancy
})

dont need ng-annotate

.controller('myController', [ 'serviceA', 'factoryB', 'filterC', function (serviceA, factoryB, filterC){
  //something fancy
}])
Community
  • 1
  • 1
maurycy
  • 8,455
  • 1
  • 27
  • 44