Search code examples
angularjsmavenminify

Maven and Angular - minify routes


I have a project in Maven with angularJS routes; login.routes.js appears like this:

(function() {
    "use strict";
    angular
        .module("app")
        .config(['$stateProvider', loginConfig]);

    function loginConfig($stateProvider) {

        $stateProvider
            .state("login", {
                url: "/login",
                templateUrl: "app/login/login.html",
                controller: "LoginController",
                controllerAs: "vm",
            })

        .state("logged", {
            [...]
            resolve: {
                checkLogged: function($log, $timeout, $state, $cookies, $rootScope) {
                    $timeout(function() {
                        if ($cookies.get('user')) {
                            [...]
                        } else {
                            [...]
                            $state.go('login');

                        }
                    }, 0)

                }
            }
        })

        .state("logout", {
            [...]
            resolve: {
                checkLogged: function($log, $timeout, $state, $cookies, $rootScope, $location) {

                   [...]

                }
            }
        })


    }
})();

I'm minifing all the angularJS files; actually, everything works minified but the routes.

Is there a way to make the code minifiable? I minified with success controllers using

angular
        .module("app")
.controller("Controller", Controller);

Controller.$inject = ['$log',...];

Is there something like that, but for routes?


Solution

  • One way to do it is in the below example:

     checkLogged: ['$log', '$timeout', '$state', '$cookies', '$rootScope', 
        function($log, $timeout, $state, $cookies, $rootScope) {
            //code
    
        }
     ] //<-- array
    

    Wrap your function in an array and inject each AngularJs provider as a string. This should solve your minification issues.

    Also this is an AngularJs question not Angular. You may want to update your tag. Hope that helps.