I have debug="true"
in both my web.config(s), and I just don't want my bundles minified, but nothing I do seems to disable it. I've tried enableoptimisations=false
, here is my code:
//Javascript
bundles.Add(new ScriptBundle("~/bundles/MainJS")
.Include("~/Scripts/regular/lib/mvc/jquery.validate.unobtrusive.js*")
.Include("~/Scripts/regular/lib/mvc/jquery.validate*")
.Include("~/Scripts/regular/lib/bootstrap.js")
.IncludeDirectory("~/Scripts/regular/modules", "*.js", true)
.IncludeDirectory("~/Scripts/regular/pages", "*.js", true)
.IncludeDirectory("~/Scripts/regular/misc", "*.js", true));
//CSS
bundles.Add(new StyleBundle("~/bundles/MainCSS")
.Include("~/Content/css/regular/lib/bootstrap.css*")
.IncludeDirectory("~/Content/css/regular/modules", "*.css", true)
.IncludeDirectory("~/Content/css/regular/pages", "*.css", true))
There is also some simple way to control minification (and other features) manually. It's new CssMinify() transformer using, like this:
That's convenient when you want to have some bundles special part only to be minified. Let's say, you are using some standard (jQuery) styles, which are getting under your feet (taking lots of excessive browser requests to them), but you want to keep unminified your own stylesheet. (The same - with javascript).
Conditional compilation directives are your friend:
If you're using LESS/SASS CSS transformation there's an option
useNativeMinification
which can be set to false to disable minification (in web.config). For my purposes I just change it here when I need to, but you could use web.config transformations to always enable it on release build or perhaps find a way modify it in code.Tip: The whole point of this is to view your CSS, which you can do in the browser inspect tools or by just opening the file. When bundling is enabled that filename changes on every compile so I put the following at the top of my page so I can view my compiled CSS eaily in a new browser window every time it changes.
this will be a dynamic URL something like
https://example.com/Content/css/bundlename?v=UGd0FjvFJz3ETxlNN9NVqNOeYMRrOkQAkYtB04KisCQ1
Update: I created a web.config transformation to set it to true for me during deployment / release build
You can turn off minification in your bundles simply by Clearing your transforms.
I personally found this useful when wanting to bundle all my scripts in a single file but needed readability during debugging phases.
This may become useful to someone in the future as the new framework, when setup through VS, gets a default
web.config
,web.Debug.config
andweb.Release.config
. In theweb.release.config
you will find this line:this was seeming to override any inline changes I made. I commented this line out and we were gravy (in terms of seeing non-minified code in a "release" build)
If you have
debug="true"
in web.config and are usingScripts/Styles.Render
to reference the bundles in your pages, that should turn off both bundling and minification.BundleTable.EnableOptimizations = false
will always turn off both bundling and minification as well (irrespective of the debug true/false flag).Are you perhaps not using the
Scripts/Styles.Render
helpers? If you are directly rendering references to the bundle viaBundleTable.Bundles.ResolveBundleUrl()
you will always get the minified/bundled content.