Customizing .NET 4.5 bundler/minifier

烈酒焚心 提交于 2019-12-11 03:58:07

问题


Is there a way to customize the output of the JavaScript minfier/bundler that comes with .NET 4.5 (Microsoft.Web.Optimization) with various minification options? For example, I want to allow local variable renaming but not allow function argument renaming.

As a background, I'm trying to introduce an AngularJS app into a .NET application, and want to be able to use the bundling/minification framework that comes with .NET 4.5. I don't want function argument renaming to happen since AngularJS uses the argument names for doing dependency injection.


回答1:


AngularJs already can handle that for you via the [] syntax option when building up controllers or other angular services

app.controller("MyCtrl", function($scope, $http){});

becomes

app.controller("MyCtrl", ["$scope", "$http", function($scope, $http){
}];

Or via $inject

var myCtrl = function($scope, $http){};

myCtrl.$inject = ['$scope', '$http'];

Doing this allows Angular to know which pieces to inject even when the js is minified.




回答2:


A similar but older question indicates you can change the transform for a specific bundle to avoid renaming.

System.Web.Optimization making function argument names stay the same for certain functions

Not sure if this is still applicable +1 year later...



来源:https://stackoverflow.com/questions/17410012/customizing-net-4-5-bundler-minifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!