Web optimizer .net core

706 views Asked by At

Upgrading .net 4.8 mvc app to .net 6. I am keeping the static content in the same folders as in the previous web app project and using the web optimizer to minify and bundle.

I am seeing lot of console errors and the UI is not loading for the app

enter image description here

Layout cshtml enter image description here

Script and Content folder

enter image description here

enter image description here

1

There are 1 answers

7
Ruikai Feng On

It may help if you could show how you configured in program.cs

I tried as the document :

In program.cs:

builder.Services.AddWebOptimizer(x =>x.AddJavaScriptBundle("/js/bundle.js", "js/chat/*.js"));

call

app.UseWebOptimizer();

before:

app.UseStaticFiles();

in chat.js:

console.log("chat");

in hellow.js:

console.log("hellow");

And my project:

enter image description here

in my View,I called:

<script src="/js/bundle.js"></script>

The result:

enter image description here

other document may help:

Update:

I tried to add two floders under the directory of the project as your comment and tried as below to fix the 404 error:

var provider1 = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "Script1"));
    var provider2 = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "Script2"));
builder.Services.AddWebOptimizer
(x =>
 {    
x.AddJavaScriptBundle("/bundle1.js","/chat/*.js").UseFileProvider(provider1); 
   x.AddJavaScriptBundle("/bundle2.js","/comment/*.js").UseFileProvider(provider2);
});

My project:

enter image description here