ligershark / WebOptimizer

A bundler and minifier for ASP.NET Core
Apache License 2.0
768 stars 114 forks source link

Minifying bundles does not work. #203

Open bkoltoniak opened 2 years ago

bkoltoniak commented 2 years ago

Minifying bundles does not work. I am using ligershark.weboptimizer.core 3.0.330 with ASP.NET Core 6.0.

App pipeline looks like below

var app = builder.Build();

        // HTTP request pipeline configuration
        if (app.Environment.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseWebOptimizer();
        app.UseStaticFiles();
        app.UseRouting();
        app.UseAuthorization();
        app.MapDefaultControllerRoute();

        await app.RunAsync();

registration of bundles

 builder.Services.AddWebOptimizer(pipeline =>
        {
            pipeline.AddCssBundle("/css/bundle.css", "/css/site.css", "/lib/bootstrap/css/bootstrap.css");
            pipeline.AddJavaScriptBundle("/js/bundle.js", "/js/site.js", "/lib/bootstrap/js/bootstrap.js");
            pipeline.MinifyCssFiles();
            pipeline.MinifyJsFiles();
        });

In dev tools I can see that files are bundled but not minified. Any Ideas how to resolve this?

bkoltoniak commented 2 years ago

Looks like the problem occurs only when bootstrap files are added to bundle. If I replaced them with my own scripts and the minification works correctly. No exception occurs while bootstrap is bundled. Maybe bootstrap files are too large? 5k lines for js and 11k lines for css.

Mohamed-Wahby commented 2 years ago

I had a similar problem. Finally I realized that they were minifyed, but the / ! comments in the css scripts made the bundle look non-minifyed. By changing them into / comments, the bundle looked totally minifyed. I hope this helps.