This can be solved better from a different direction - instead of not trying to minimize one file, instead add transformations for individual elements.
First create a class that implements IItemTransform and uses the same code to minimize the given input:
public class JsItemMinify : System.Web.Optimization.IItemTransform { public string Process(string includedVirtualPath, string input) { var min = new Microsoft.Ajax.Utilities.Minifier(); var result = min.MinifyJavaScript(input); if (min.ErrorList.Count > 0) return "/*minification failed*/" + input; return result; } }
Second - add this item to separate files and remove the package conversion:
var commonBundle= new Bundle("~/CommonJS"); // the first two includes will be minified commonBundle.Include("~/Scripts/jquery-1.7.2.js", new JsItemMinify()); commonBundle.Include("~/Scripts/jquery-ui-1.8.22.js", new JsItemMinify()); // this one will not commonBundle.Include("~/Scripts/jquery.cookie.js"); // Remove the default JsMinify bundle transform commonBundle.Transforms.Clear(); BundleTable.Bundles.Add(commonBundle);
Knaģis
source share