WebOptimizer
WebOptimizer copied to clipboard
Bundle files without minifying them
Hi,
from your main site: "Bundling is the process of taking multiple source files and combining them into a single output file. All CSS and JavaScript bundles are also being automatically minified."
I want to debug my code during development thus I do not want minified code, but I want it bundled as my index.cshtml file always references a single all.js file.
How can I disable the minification of a bundle?
Instead of using AddJavaScriptBundle(...) use a custom pipeline:
pipeline.AddBundle("/js/bundle.js", "text/javascript; charset=UTF-8", "/js/a.js", "/js/b.js")
.Concatenate(); // This is what makes the bundle
I would say that passing a "CodeSettings" instance to the AddJavaScript bundle like
pipeline.AddJavaScriptBundle("/bundle-frontend.js",
new CodeSettings()
{
MinifyCode = false
},
"/js/helper.analytics.js",
"/js/view.frontend.site.js",
);
Should be respected, right now it's not
I just made a copy of it to solve this temporary:
public static IAsset AddJsBundle(
this IAssetPipeline pipeline,
string route,
CodeSettings settings,
params string[] sourceFiles)
{
if(settings.MinifyCode)
return pipeline.AddBundle(route, "text/javascript; charset=UTF-8", sourceFiles)
.EnforceFileExtensions(".js", ".jsx", ".es5", ".es6")
.Concatenate()
.AddResponseHeader("X-Content-Type-Options", "nosniff")
.MinifyJavaScript(settings);
return pipeline.AddBundle(route, "text/javascript; charset=UTF-8", sourceFiles)
.EnforceFileExtensions(".js", ".jsx", ".es5", ".es6")
.Concatenate()
.AddResponseHeader("X-Content-Type-Options", "nosniff");
}
Any chance this will be implemented/fixed? The AddJavaScriptBundle does not allow to prevent the file from being minified even if you pass the settings.
Submitted https://github.com/ligershark/WebOptimizer/pull/245 to try and address this
Can't wait to get this fix in the next nuget.
The fix I did has now been released which I thought I'd put here as I checked on it today