2

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.

govin
  • 6,445
  • 5
  • 43
  • 56
  • Duplicate of http://stackoverflow.com/questions/14909541/mvc4-bundling-minification-and-angularjs-services – drzaus Nov 12 '13 at 18:07

2 Answers2

2

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.

Mark Coleman
  • 40,542
  • 9
  • 81
  • 101
  • 1
    Thanks Mark. I'm trying to avoid writing myCtrl.$inject for each controller since it looks like boilerplate code for the sake of minifier. Plus we also have to write additional code which adds to JavaScript size. So wondering if there would be an option to customize this (whether to apply function argument renaming or not) in the .NET web optimization framework itself. – govin Jul 01 '13 at 17:46
1

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...

Community
  • 1
  • 1
drzaus
  • 24,171
  • 16
  • 142
  • 201