Angular minimization with grunt results in "Error creating module" error

I know about setting up the controller, service, model, etc. to prepare to a minimum. I have about 20 controllers, models and services as separate files, and I want to minimize them and combine them into one JS file for production.

To find out how to configure these files, here is an example:

VforumJS.controller('MainController', ['$scope', '$location', '$sce', 'MainModel', 'LogModel', 'MainDebug', 'timecode', 'Idle', function($scope, $location, $sce, MainModel, LogModel, MainDebug, timecode, Idle)
{
  ...
}]);

After minimizing, I get an error

Failed to instantiate module VforumJS due to:
  Error: [$injector:unpr] http://errors.angularjs.org/1.4.1/$injector/unpr?p0=a

If I click on the error link, it says Unknown provider: a

Here my module is created

var VforumJsConfig = function($routeProvider, $locationProvider, localStorageServiceProvider)
{
  localStorageServiceProvider.setPrefix('vforumdesktop');
  $locationProvider.html5Mode(true);

  $routeProvider
  .when('/', {
    ...
  })
  .otherwise({
    ...
  });
};

var VforumJS = angular.module('VforumJS', ['ngRoute','LocalStorageModule', 'ngTouch', 'ui-rangeSlider','base64','ngIdle'])
.config(['$routeProvider', '$locationProvider', 'localStorageServiceProvider', VforumJsConfig])
.constant('LogTypes', {
  LOGIN:          1,
  IDLE_LOGOUT:    2,
  MANUAL_LOGOUT:  3,
  VFORUM_OPEN:    4,
  VFORUM_CLOSE:   5
})
.constant('SendLogs', false)
.constant('MainDebug', true);

Perhaps I am not doing the correct minification preparation in the above code, where is the module created?

Here is my Gruntfile.js

'use strict';

module.exports = function(grunt)
{
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    uglify: {
      all_src: {
        options: {
          sourceMap: true,
          sourceMapName: 'source.map'
        },
        src: 'resources/js/**/*.js',
        dest: 'composite.all.min.js'
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.registerTask('default', ['uglify']);
};
+4
source share
2 answers

.config . , /, -.

, , ( $logProvider ), :

.config(function(a){
  console.log("Never gets here, but a is", a);
})

:

.config(['$logProvider', function(a){
  console.log("a is", a);
}])

: http://codepen.io/troylelandshields/pen/xGjKGV

+1

VforumJsConfig

var VforumJsConfig = function($routeProvider, $locationProvider, localStorageServiceProvider)

minified, angular , . ( ), .

: https://docs.angularjs.org/tutorial/step_05#a-note-on-minification

, VforumJsConfig:

VforumJsConfig.$inject = ['$routeProvider', '$locationProvider', 'localStorageServiceProvider']
0

All Articles