ligershark / WebOptimizer

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

Lazy creation of javascript bundles #289

Closed tskong closed 8 months ago

tskong commented 8 months ago

Hi,

I'm creating javascript bundles dynamically by reading out embedded js files from assemblies, the problem I have is that the assemblies are loaded much later on in the custom booting code, so they aren't available in the ConfigureServices() method. Is there a way to lazy create the javascript bundles, almost on demand, or at least after the ConfigureServices() ?

Thanks

  ```
  services.AddWebOptimizer(pipeline =>
            {
                var embeddedprovider = new EmbeddedFileProvider(assembly);
                var jsfiles = embeddedprovider.GetDirectoryContents("").Where(x => x.Name.EndsWith("js")).Select(b => b.Name).ToArray();
                if (jsfiles.Any())
                {
                    var f = Path.GetFileName(assembly.Location).Split(".");

                    pipeline.AddJavaScriptBundle("/js/" + f[3].ToLower(), jsfiles)
                        .UseFileProvider(embeddedprovider);
                }
            }
tskong commented 8 months ago

I've found another way of doing it, closing issue