Browse Source

Add methods to remove bundle files by name or predicate

Resolve #23169

```cs
Configure<AbpBundlingOptions>(options =>
{
    options.ScriptBundles
        .Configure(typeof(ManageModel).FullName,
            configuration =>
            {
                configuration.RemoveFiles("/Pages/Account/Default.js");
            });
});
```
pull/23175/head
maliming 8 months ago
parent
commit
f7678914d6
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 12
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs
  2. 30
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollection.cs
  3. 15
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs

12
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationExtensions.cs

@ -23,6 +23,18 @@ public static class BundleConfigurationExtensions
return bundleConfiguration;
}
public static BundleConfiguration RemoveFiles(this BundleConfiguration bundleConfiguration, params string[] files)
{
bundleConfiguration.Contributors.RemoveBundleFile(files.ToArray());
return bundleConfiguration;
}
public static BundleConfiguration RemoveFiles(this BundleConfiguration bundleConfiguration, Func<string, bool> predicate)
{
bundleConfiguration.Contributors.RemoveBundleFile(predicate);
return bundleConfiguration;
}
public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params IBundleContributor[] contributors)
{
Check.NotNull(contributors, nameof(contributors));

30
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollection.cs

@ -76,6 +76,36 @@ public class BundleContributorCollection
}
}
public void RemoveBundleFile(string fileName)
{
RemoveBundleFile([fileName]);
}
public void RemoveBundleFile(string[] fileNames)
{
var contributors = _contributors
.Where(x => x is BundleFileContributor bundleContributor &&
bundleContributor.Files.Any(f => fileNames.Any(name => name.Equals(f.FileName, StringComparison.OrdinalIgnoreCase))))
.Cast<BundleFileContributor>();
foreach (var contributor in contributors)
{
contributor.Files.RemoveAll(x => fileNames.Any(name => name.Equals(x.FileName, StringComparison.OrdinalIgnoreCase)));
}
}
public void RemoveBundleFile(Func<string, bool> predicate)
{
var contributors = _contributors
.Where(x => x is BundleFileContributor bundleContributor &&
bundleContributor.Files.Any(f => predicate(f.FileName)))
.Cast<BundleFileContributor>();
foreach (var contributor in contributors)
{
contributor.Files.RemoveAll(x => predicate(x.FileName));
}
}
public IReadOnlyList<IBundleContributor> GetAll()
{
return _contributors.ToImmutableList();

15
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleContributorCollectionExtensions.cs

@ -1,4 +1,7 @@
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using System;
using System.Linq;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling;
public static class BundleContributorCollectionExtensions
{
@ -16,4 +19,14 @@ public static class BundleContributorCollectionExtensions
{
contributors.Add(new BundleFileContributor(files));
}
public static void RemoveFile(this BundleContributorCollection contributors, params string[] files)
{
contributors.RemoveBundleFile(files.ToArray());
}
public static void RemoveFile(this BundleContributorCollection contributors, Func<string, bool> predicate)
{
contributors.RemoveBundleFile(predicate);
}
}

Loading…
Cancel
Save