Custom script conversion in ASP.NET MVC package is ignored when debug is false and a file with a mini file exists

I am working on an MVC 5.0 application (.Net 4.5) where I need to apply a custom JavaScript conversion to my included package files. One of these files, which I call dummy.js for illustration, has a miniature file called dummy.min.js.

I created my own script conversion to replace nested links window.jQuerywith another expression. Everything works fine when I run locally and in debug mode, but when debug mode is disabled in the Web.config file, the Bundle returns the contents of the dummy.min.js file, but my script conversion does not apply to This. It applies only to JavaScript files that do not have an associated .min.js file.

Does anyone have an idea on how to resolve this? This is almost like an error in MVC.

The workaround is to delete the mini file. This post relates to my situation, suggesting deleting the file .min.js, since MVC is the default by default, but I'm looking for an alternative solution (if any).

Thank you so much in advance.


Here's how to reproduce above:

If you are interested in reproducing my problem, do a quick BundleConfigand actual conversion script. It replaces all instances window.jQuerywith window.$jq1_9||window.jQuery, suggesting that it is introduced through a self-signed anonymous function.

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(
            new ScriptBundle("~/bundles/dummy")
                .Include("~/Scripts/dummy.js", new InjectedJQueryVariableRewriteTransform()));
    }
}

public class InjectedJQueryVariableRewriteTransform : System.Web.Optimization.IItemTransform
{
    public string Process(string includedVirtualPath, string javaScriptCode)
    {
        // TODO: I understand this approach is naiive, but it does the trick for now.
        return javaScriptCode.Replace("window.jQuery", "window.$jq1_9 || window.jQuery");
    }
}

Visual Studio 2012 MVC 4, 1.1.0 System.Web.Optimization, , Nuget. 1.1.2 .

Install-Package Microsoft.AspNet.Web.Optimization

JavaScript dummy.js. dummy.min.js:

(function ($) {
    "use strict";

    // TODO: Do something interesting...
})(window.jQuery);

debug false Web.config:

<compilation debug="false" targetFramework="4.5" />

, 9221, Firefox Chrome:

http://localhost:9221/bundles/dummy

, debug true, , :

(function(){"use strict"})(window.$jq1_9||window.jQuery) 

false. .min.js:

(function(){"use strict"})(window.jQuery)
+3
1

:

bundles.FileExtensionReplacementList.Clear();

.min . , , , - , . , .

, EnableFileExtensionReplacements false :

var bundle = new ScriptBundle("...");
bundle.EnableFileExtensionReplacements = false;
+5

All Articles