Bundler Not Including .Min Files

Bundler not including .min files

The solution I originally posted is questionable (is a dirty hack). The tweaked behaviour has changed in Microsoft.AspNet.Web.Optimization package and the tweak does not work anymore, as pointed out by many commenters. Right now I cannot reproduce the issue at all with the version 1.1.3 of the package.

Please see sources of System.Web.Optimization.BundleCollection (you can use dotPeek for example) for better understanding of what you are about to do.
Also read Max Shmelev's answer.

Original answer:

Either rename .min.js to .js or do something like

    public static void AddDefaultIgnorePatterns(IgnoreList ignoreList)
{
if (ignoreList == null)
throw new ArgumentNullException("ignoreList");
ignoreList.Ignore("*.intellisense.js");
ignoreList.Ignore("*-vsdoc.js");
ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);
//ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled);
ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
}

public static void RegisterBundles(BundleCollection bundles)
{
bundles.IgnoreList.Clear();
AddDefaultIgnorePatterns(bundles.IgnoreList);
//NOTE: it's bundles.DirectoryFilter in Microsoft.AspNet.Web.Optimization.1.1.3 and not bundles.IgnoreList

//...your code
}

Asp.Net bundling not using the .min files

It seems that in case of a ScriptBundle the library does not do what it should and tries to minify any file. I changed it to just Bundle and that seems to make the trick and load the preminified versions.

Found the answer here: Style bundling for MVC4 not using min files

MVC JS Bundle not including all files

Please refer this Link

and try this code it's work for me in my project very first I'm adding min file in bundles it's not including then I'm added this line.

BundleTable.EnableOptimizations = true;

 public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/myJS").Include(
"~/myJS/getPathforAjax.js",
"~/myJS/dropdown.js",
"~/myJS/email8.js",
"~/myJS/main-nav-click.js"
));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/site.css"
,"~/Content/caption.css"
, "~/Content/dropdown.css"
, "~/Content/colors.css"
, "~/Content/buttons.css"
, "~/Content/stripe.css"));

// Code removed for clarity.
BundleTable.EnableOptimizations = true;
}

Style bundling for MVC4 not using min files

I had the exact same issue you had, my solution contained css/js files accompanied by their .min files that I had used Web Essentials to minimize.

If I used the bundles in debug mode, everything would work correctly and all of the individual non-minimized files would be loaded in my app. However, if I set BundleTable.EnableOptimizations = true; then I would get errors because it had trouble minimizing my files.

Based on http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification where it states:

For ASP.NET MVC 4, this means with a debug configuration, the file
jquery-1.7.1.js will be added to the bundle. In a release
configuration, jquery-1.7.1.min.js will be added. The bundling
framework follows several common conventions such as:

Selecting “.min” file for release when “FileX.min.js” and “FileX.js”
exist. Selecting the non “.min” version for debug.

I expected it to simply load up my already minimized files and just bundle them. What I believe is implied, but missing in the documentation, is that it will also again minimize my already minimized files, which wasn't working and causing errors in the output.

I found http://aspnetoptimization.codeplex.com/workitem/56 which mentions:

You can skip minification simply by creating bundles with no
transform, i.e. don't create ScriptBundles, just normal Bundles.

This turned out to be the answer to my issue. By setting both my ScriptBundle and StyleBundle to just type Bundle, I now get the correct bundling without the minimizing.

In debug, all of my regular css/jss files are loaded indidivually. When I set it to non-debug, everything is bundled and it automatically chooses all of the .min files.

MVC Bundling - Include .min file for a single bundle

A quick fix is to rename the js file taking out .min. Or as per the solution in this link you can create your own ignore patterns.

https://stackoverflow.com/a/12005272/1593273

MVC minification not including a file unless I modify it a certain way

This seems to work with the latest versions of Microsoft.AspNet.Web.Optimization and WebGrease:

  • Microsoft.AspNet.Web.Optimization 1.1.3
  • WebGrease 1.5.2

With those versions, creating a bundle as follows works fine:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/underscore/underscore.js",
"~/Scripts/underscore/underscore.string.min.js"
));

While this doesn't explain the issue, upgrading to the latest versions will fix it.



Related Topics



Leave a reply



Submit