Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 7: Development environmet disable bundling not working #293

Open
heimzza opened this issue Nov 24, 2023 · 2 comments
Open

.NET 7: Development environmet disable bundling not working #293

heimzza opened this issue Nov 24, 2023 · 2 comments

Comments

@heimzza
Copy link

heimzza commented Nov 24, 2023

This is how i use in program.cs

builder.Services.AddWebOptimizer(pipeline =>
    {
        pipeline.AddCssBundle("~/Content/styles/css",
                              "Content/styles/vendor.css",
                              "Content/styles/main.css",
                              "Content/styles/widget-menu.css",
                              "Content/styles/launcher.css");
    
        pipeline.AddJavaScriptBundle("~/Content/scripts/js",
                                     "Content/scripts/vendor/modernizr.js",
                                     "Content/scripts/vendor.js",
                                     "Content/scripts/plugins/inputMask.js",
                                     "Content/scripts/plugins/timeago/jquery.timeago.js",
                                     "Content/scripts/LanguageData.js",
                                     "Content/scripts/languageHelper.js",
                                     "Content/scripts/vendor/domPurify/purify.js",
                                     "Sdk/SocketConnection.js",
                                     "Content/scripts/main.js");
    
        pipeline.AddJavaScriptBundle("~/Content/scripts/js_noemoji",
                                     "Content/scripts/vendor/modernizr.js",
                                     "Content/scripts/vendor.noemoji.min.js",
                                     "Content/scripts/plugins/inputMask.js",
                                     "Content/scripts/plugins/timeago/jquery.timeago.js",
                                     "Content/scripts/LanguageData.js",
                                     "Content/scripts/languageHelper.js",
                                     "Content/scripts/vendor/domPurify/purify.js",
                                     "Sdk/SocketConnection.js",
                                     "Content/scripts/main.js");
    },
    option =>
    {
        option.EnableCaching = true;
        option.EnableDiskCache = false;
        option.EnableMemoryCache = true;
        option.AllowEmptyBundle = true;
    });

if (builder.Environment.IsDevelopment())
{
    builder.Services.AddWebOptimizer(minifyJavaScript: false, minifyCss: false);
}

and in app.use section

app.UseCors(builder => builder.AllowAnyOrigin());

app.UseHttpsRedirection();

app.UseWebOptimizer();

app.UseStaticFiles();

app.UseSession();

It is still bundling and minifying the javasxript files. Even if i do rebuild it does not change.

Can you help me please?

@heimzza heimzza changed the title .NET 7: Development environmet disable bundling not workibg .NET 7: Development environmet disable bundling not working Dec 2, 2023
@osjoberg
Copy link

osjoberg commented Jan 31, 2024

I got it working by doing the following changes:

Remove:

if (builder.Environment.IsDevelopment())
{
builder.Services.AddWebOptimizer(minifyJavaScript: false, minifyCss: false);
}

Add:

option.EnableTagHelperBundling = !builder.Environment.IsDevelopment();

@barts2108
Copy link

That solution did not even work for me as I not use any bundling.

I had

builder.Services.AddWebOptimizer(pipeline => {
        pipeline.MinifyJsFiles("js/site.js", "js/site_tagify.js", "lib/jquery-unobtrusive-ajax/jquery.unobtrusive-ajax.js");
        pipeline.MinifyCssFiles("css/site.css", "css/dark.css", "css/backdrop.css");
});
        
if (builder.Environment.IsDevelopment())
{
    builder.Services.AddWebOptimizer(minifyCss: false, minifyJavaScript: false);
}

with some experimenting after finding this thread changed it to:

builder.Services.AddWebOptimizer(minifyCss: !builder.Environment.IsDevelopment(), minifyJavaScript: !builder.Environment.IsDevelopment());

builder.Services.AddWebOptimizer(pipeline => {
        pipeline.MinifyJsFiles("js/site.js", "js/site_tagify.js", "lib/jquery-unobtrusive-ajax/jquery.unobtrusive-ajax.js");
        pipeline.MinifyCssFiles("css/site.css", "css/dark.css", "css/backdrop.css");
    }
);

Which seems to work ... Looks like the order of appearance is important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants