WebOptimizer icon indicating copy to clipboard operation
WebOptimizer copied to clipboard

Bundle files without minifying them

Open LisaTatum opened this issue 7 years ago • 6 comments

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?

LisaTatum avatar Dec 09 '17 00:12 LisaTatum

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

hellfirehd avatar Mar 21 '18 01:03 hellfirehd

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");
        }

enkelmedia avatar Apr 13 '21 15:04 enkelmedia

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.

felovala avatar May 02 '22 21:05 felovala

Submitted https://github.com/ligershark/WebOptimizer/pull/245 to try and address this

TechLiam avatar Aug 12 '22 10:08 TechLiam

Can't wait to get this fix in the next nuget.

cadilhac avatar Aug 21 '22 15:08 cadilhac

The fix I did has now been released which I thought I'd put here as I checked on it today

TechLiam avatar Oct 06 '22 19:10 TechLiam