Webpack Uglify 导致路由停止工作 [英] Webpack Uglify causes routing to stop work

查看:34
本文介绍了Webpack Uglify 导致路由停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我丑化 webpack 包时,路由停止工作,没有任何错误消息或日志消息.我正在使用 oclazyload 进行延迟加载.

When I uglify webpack bundle, routing stops work without any error message or log message. I am using oclazyload to lazy load.

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.依赖项被安全地注入到缩小的文件中.

When I minify the bundle, app routing stops working. Otherwise it works fine. Please provide me a solution. Also I am using ngAnnotate. Dependencies are injected safely in minified file.

推荐答案

您使用的是最新版本的 ui-router,它具有更新且略有不同的 resolve 块处理方式.它需要一个对象映射.

You're using the latest version of ui-router, which has a newer and slightly different way of handling the resolve block. It takes an object map.

试试这个:

    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

Here is the ui-router API doc for this: https://github.com/angular-ui/ui-router/wiki#resolve

这篇关于Webpack Uglify 导致路由停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆