System.Web.Optimization使函数参数名对于某些函数保持不变

And*_*oth 5 asp.net-mvc asp.net-optimization

使用ASP.NET捆绑ScriptBundle

function StartController($scope, $location, $rootScope) {}
Run Code Online (Sandbox Code Playgroud)

变成了

function StartController(n,t,i) {}
Run Code Online (Sandbox Code Playgroud)

但是,由于我使用的是AngularJs,因为依赖注入仍然有效,因此在缩小时不得更改参数名称.我怎样才能确保$ scope,$ location和$ rootScope通过ScriptBundle保持这些名称的缩小,但是允许在其他地方重命名参数?

Hao*_*ung 3

这不是您可以在内置捆绑类型上更改的内容,因为我们目前没有公开任何您可以在底层转换类上调整的旋钮。实现此目的的最佳方法是编写自己的 IBundleTransform,它会在适当的设置中进行缩小传递,以免重命名变量。

即类似:

public class CustomTransform : IBundleTransform {
    public void process(BundleContext context, BundleResponse response) {
         response.Content = MyMinifier.MinifyWithoutRename(response.Content);
    }
}

BundleTable.Bundles.Add(new Bundle("~/bundles/mybundle", new CustomTransform());
Run Code Online (Sandbox Code Playgroud)

  • 事实证明,Angular 还有其他符号可以让他们的 DI 与压缩器一起使用 http://docs.angularjs.org/guide/di。 (3认同)
  • 这仍然适用吗?什么是“MyMinifier”? (2认同)