问题
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