Custom script transform in ASP.NET MVC bundle ignored when debug is false and minified file exists -


I am working on an MVC 5.0 (.Net 4.5) application where I implement a custom javascript transform in my javascript Bundle files will be one of those files, which I am calling dummy.js for imaging purposes, has a minified file called dummy.min.js .

I changed a custom script to replace the injection window.jQuery references with a different expression. When I run locally and in debug mode, everything works fine, but when the web If the debug mode is closed in the config file, the bundle returns the content of the dummy.min.js file, but my script does not apply to it, this applies only to javascript files which is not has an associated .min.js file.

How can anyone know this? It almost looks like a bug in MVC.

A solution is to remove a minified file, by suggesting that I remove the .min.js file from my status, because I think MVC delivers by default, But I'm looking for an alternative solution (if any).

Thank you very much in advance.


The above can be reproduced:

If you are interested in removing my problem, here is a quick < Code> bundle config and convert to the actual custom script it changes all the instances of the window with window.jQuery . $ Jq1_9 || Window.jQuery , it is injected with self-implemented anonymous function. Public Sector Bundle Confief {Public Stable Zero Register Bundle (Bundle Collection Bundle) {Bundle. Add ("~ / / scripts / dummy .js"), new injected queerable reactive transformation ());) (Add new scriptbundle ("~ / bundle / dummy"). }} Public Square Injected Genetically Modified Transform: Systems Web. Optimization. IETMtransform {public string process (string includes virtualpath, string javaScriptCode) {/ TODO: I think this approach is new, but it's a trick for now. Return javaScriptCode.Replace ("window.jQuery", "window. $ Jq1_9 || window.jQuery"); }}

If you have Visual Studio 2012 and MVC 4 , then you have version 1.1.0 System.Web.Optimization assembly, which you can get by running the following commands in the Nuget Package Manager. This version of package installs 1.1.2 at the time of typing.

Install-package Microsoft.AspNet.Web.Optimization

Here the sample javascript is dummy.js . You can make a copy of it and name it as dummy.min.js :

  (function ($) {"strict use"; / / TODO: Something interesting ...}) (window.jQuery);  

Set the debug attribute to false in the following element in Web.config:

  Lt; Compilation debug = "false" targetFramework = "4.5" />  

Introducing the bundle of the application in the 9221, Firefox, or Chrome ports of the application:

  http: // localhost: 9221 / bundle / dummy < / Code> 

You will see that when debugs is set to true , then the transform is applied, as shown below:

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

When this false is ignored and that only use the .min.js file

(function () {"use strict"}) (window.jQuery)

If you add this line:

  bundles. File Extension Replacement List Clear ();  

You will remove the rules to use .min files when bundling is enabled. You will remove all the rules, unfortunately, so if you want someone else you need to add manually. Apart from this, it will change the rules of all bundles.

If you want to disable these replacement rules only for one bundle, then you can set the EnableFileExtensionReplacements property on the specific bundle to the wrong:

  Var bundle = new scriptbundle ("..."); Bundle Enabled file extension device = wrong;  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -