【问题标题】:AngularJS with .NET MVC Bundling Minification Error带有 .NET MVC 捆绑缩小错误的 AngularJS
【发布时间】:2015-04-17 17:06:20
【问题描述】:

我一直在 .NET MVC 网站内开发一个大型 AngularJS 应用程序。我已经很久没有测试它是否会使用捆绑优化功能成功缩小?

BundleTable.EnableOptimizations = True

当然,它失败了。我一直在玩我捆绑脚本的顺序,并确保我使用字符串文字作为我的控制器名称(我没有,这是我必须做的很多重构)。

但是如果没有角度“未知提供者”错误,我无法让我的核心脚本 Minifiy。

这是确切的错误: 未捕获的错误:[$injector:modulerr] [http://errors.angularjs.org/1.3.14/$injector/modulerr?p0=ppAccount&p1=Error...redScripts%3Fv%3DknV3wkCOg32ajaw4GwiRSrTXdo8Ue7MRIn65CPYa1b81%3A1%3A379851)]1

这是我失败的捆绑配置:

            bundles.Add(new ScriptBundle("~/bundles/PilotPartnerRequiredScripts")
      .Include(
          "~/UI/js/jquery/jquery-2.1.3.js",
          "~/UI/js/plugins/jquery-ui/jquery-ui.js",
          "~/UI/js/bootstrap/bootstrap.js",
          "~/UI/js/plugins/pace/pace.min.js",
          "~/UI/js/plugins/slimscroll/jquery.slimscroll.js",
          "~/UI/js/inspinia.js",
          "~/UI/js/angular/angular.js",
          "~/UI/js/ui-router/angular-ui-router.js",
          "~/UI/js/bootstrap/ui-bootstrap-tpls-0.12.1.js",
          "~/UI/js/angular/angular-resource.js",
          "~/UI/js/angular/angular-sanitize.js",
          "~/UI/js/angular/angular-route.js",
          "~/UI/js/plugins/switchery/switchery.js",
           "~/UI/js/plugins/angular-ui-switch/angular-ui-switch.js",
           "~/UI/js/plugins/angularLocalStorage/angular-local-storage.js",
           "~/UI/js/plugins/ngDialog/ngDialog.js",
           "~/Scripts/ngTags/ng-tags-input.js",
           "~/Scripts/uiSortable/sortable.js",
           "~/Scripts/kendo/2014.3.1119/kendo.all.min.js",
           "~/Scripts/xeditable/xeditable.js"

对于我的一生,我无法弄清楚哪个依赖项没有得到解决。我觉得如果我能把它缩小到一个特定的依赖,我知道我可以解决这个问题。

有没有办法追踪导致问题的特定模块?

关于如何进行这项工作的任何建议?

感谢您的帮助。

【问题讨论】:

  • 您的注射在 Angular 中是否安全?

标签: asp.net-mvc angularjs bundle


【解决方案1】:

在注入依赖项时应始终遵循严格的 di(数组表示法)

Angular Doc 提到,在进行缩小时一定要遵循严格的 DI,否则可能会破坏您的应用程序

例如(代码)

angular.module('myModule', [])
.factory('serviceId', ['depService', function(depService) {
  // ...
}])
.directive('directiveName', ['depService', function(depService) {
  // ...
}])
.filter('filterName', ['depService', function(depService) {
  // ...
}]);

在上面的 sn-p 中,我遵循了 DI 的内联数组表示法,它已应用于各种角度组件,只是为了演示它。您应该确保在注入依赖项的任何地方都遵循它。

【讨论】:

  • 我没有这样做,当它失败时,这是我开始尝试的第一件事。我浏览了整个 AngularJS 应用程序(我的整个应用程序中有多个)并将其换掉。到目前为止没有运气。有可能我错过了一个。我会坚持下去。但似乎 Angular-Animate 也给我带来了问题。它总是无法最小化。
  • 做了更多的挖掘工作。正是这样。我发现我的 App.config 没有使用 strict-DI,这导致了问题。这是我设置 $routeProvider 的地方。
猜你喜欢
  • 2014-05-22
  • 2016-09-27
  • 2017-12-13
  • 2014-11-26
  • 2014-09-29
  • 2014-04-16
  • 2018-05-11
  • 1970-01-01
  • 2013-05-05
相关资源
最近更新 更多