ligershark / WebOptimizer

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

pipeline.AddFiles does not work with Manifest Embedded file provider. #253

Closed Markuzy closed 1 month ago

Markuzy commented 1 year ago

Able to confirm whether is it bug or unsupported?

My provider is a ManifestEmbeddedFileProvider:

public static IFileProvider GetProvider()
{
    var provider = new ManifestEmbeddedFileProvider(
                assembly: typeof(Setup).Assembly, "Libraries");
    return provider;
}

The .AddJavascriptBundle line works without issue, proving that the paths are correct and the provider is working. The webpage is able to resolve the individual files from the provider without issue with this inclusion at startup.cs/program.cs (depending on your .NET version), so I am confident that the file provider is working normally.

app.Map("/my-js-path", builder =>
{
    builder.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = JsPluginHelper.GetProvider(),
    });
});

But using .AddFiles does not work with mentioned custom file provider, the page still shows unbundled individual files when requested in browser with cache off.

builder.Services.AddWebOptimizer(pipeline =>
{
    var provider = JsPluginHelper.GetProvider();
    var libPaths = JsPluginHelper.GetLibraryPaths();

    // this works for bundling
    pipeline.AddJavaScriptBundle("/dsg-plugin/combined.js", libPaths).UseFileProvider(provider).MinifyJavaScript();

    // this does not work for individual files
    foreach (var asset in pipeline.AddFiles("text/javascript", "/dsg-plugin/CategoryA/ca.js").)
    {
        asset.UseFileProvider(provider).MinifyJavaScript();
    }
});