当我uglify webpack bundle时,路由停止工作,没有任何错误消息或日志消息。我使用oclazyload来延迟加载。
Route.js
module.exports = function(app) {
var routeConfig = function($stateProvider) {
$stateProvider
.state('home', {
url: '/',
templateUrl: 'app/dashboard/dashboard.min.html',
title: 'Home',
ncyBreadcrumb: {
label: 'Home'
}
})
.state('organizationStructure', {
url: '/organizationStructure',
templateUrl: 'app/admin/organizationStructure/manageHierarchy/manageHierarchyShell.min.html',
'abstract': true,
ncyBreadcrumb: {
skip: true
},
resolve: ['$q', '$ocLazyLoad', function($q, $ocLazyLoad) {
var deferred = $q.defer();
require.ensure([], function() {
var mod = require('./organizationStructure.module.js');
$ocLazyLoad.load({
name: 'app.organizationStructure'
});
deferred.resolve(mod.controller);
});
return deferred.promise;
}]
})
.state('organizationStructure.organization', {
url: '/organization',
templateUrl: 'app/admin/organizationStructure/manageHierarchy/organization/index.min.html',
controller: 'ManageOrganization',
controllerAs: 'vm',
title: 'Manage Organization',
ncyBreadcrumb: {
label: 'Manage Organization',
parent: 'home'
}
});
}
app.config(routeConfig);
return routeConfig;
};
Module.js
var app = angular.module('app', [
'ui.router',
'restangular',
'ui.bootstrap',
'ncy-angular-breadcrumb',
'oc.lazyLoad'
]);
基本路线
require('./app.route.js')(app);
当我缩小捆绑包时,应用程序路由停止工作。否则它工作正常。请给我一个解决方案。我也在使用ngAnnotate。依赖关系会在minified文件中安全注入。
答案 0 :(得分:4)
在进行缩小时,您应该对DI进行数组注释。
您在app.js中没有使用角度数组表示法,您需要在下面进行更改。
来自
app.config(routeConfig);
要强>
app.config(['$stateProvider', routeConfig]);
有关详细信息,请参阅this SO Answer
答案 1 :(得分:3)
您正在使用最新版本的ui-router,它具有更新且略有不同的处理resolve
块的方式。它需要一个对象图。
试试这个:
resolve: {
foo: ['$q', '$ocLazyLoad', function($q, $ocLazyLoad) {
var deferred = $q.defer();
require.ensure([], function() {
var mod = require('./organizationStructure.module.js');
$ocLazyLoad.load({
name: 'app.organizationStructure'
});
deferred.resolve(mod.controller);
});
return deferred.promise;
}]
}
以下是ui-router API文档:https://github.com/angular-ui/ui-router/wiki#resolve