Mvc4捆绑,缩小和AngularJS服务 [英] Mvc4 bundling, minification and AngularJS services

查看:147
本文介绍了Mvc4捆绑,缩小和AngularJS服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来定制的方式Asp.Net MVC4捆绑和放大器;缩小功能minifies的js文件

Is there a way to customize the way Asp.Net MVC4 bundling&minification feature minifies the js files?

意思,我不想完全关闭微小,但现况它只是打破AngularJs。

Meaning, I don't want to completely turn off minification, but "as is" it just breaks AngularJs.

由于AngularJs使用DI和IoC机制在控制器注射服务,以下内容:

Since AngularJs uses DI and IoC approach for injecting services in controllers, the following:

function MyController($scope) { }

在缩小的,就变成了:

function MyController(n) { }

通常这不会是一个问题,但AngularJs使用参数名称来理解注入哪些服务。这样$范围仍应$范围,以及在角速度控制器的任何其他参数。其他的一切,像局部变量等,应能正常缩小的。

Normally that wouldn't be a problem, but AngularJs uses the parameter names to understand which service to inject. So $scope should remain $scope, as well as any other parameter in angular controllers. Everything else, like local variables, etc, should be minified normally.

我找不到如何配置Mvc4微小任何明确的文档,就显得太愚蠢了它是全有或全无,所以我觉得我失去了一些东西。

I can't find any clear documentation on how to configure Mvc4 minification, and it seems rather dumb for it to be "all or nothing" so I think I'm missing something.

感谢。

推荐答案

其实你可以(也应该!)编写AngularJS code所以它是微小安全。详情 http://docs.angularjs.org/guide/di 的依赖注解一节中,但在描述总之,对于全局定义的控制器,你可以写:

Actually you can (and should!) write AngularJS code so it is "minification safe". Details are described in the "Dependency Annotation" section of http://docs.angularjs.org/guide/di but in short, for globally defined controllers you can write:

$ myController的注入='$范围'];

请注意,全局定义控制器污染全局命名空间(见这个了解更多详细信息),并应避免。如果您在模块级声明控制器,你可以把它缩小安全以及

Please note that globally defined controllers are polluting global namespace (see this for more details) and should be avoided. If you declare a controller on a module level you can make it minification-safe as well:

angular.module('mymodule', []).controller('MyController', ['$scope', function($scope){
//controller code goes here
}]);

这篇关于Mvc4捆绑,缩小和AngularJS服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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