diff --git a/docs/en/UI/AspNetCore/Bundling-Minification.md b/docs/en/UI/AspNetCore/Bundling-Minification.md index 9d88a37135..aeaea6c2e6 100644 --- a/docs/en/UI/AspNetCore/Bundling-Minification.md +++ b/docs/en/UI/AspNetCore/Bundling-Minification.md @@ -165,7 +165,27 @@ public class MyWebExtensionModule : AbpModule } ```` -> It's not possible to configure unnamed bundle tag helpers by code, because their name are not known at the development time. It's suggested to always use a name for a bundle tag helper. +You can also use the `ConfigureAll` method to configure all existing bundles: + +````C# +[DependsOn(typeof(MyWebModule))] +public class MyWebExtensionModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options + .ScriptBundles + .ConfigureAll(bundle => { + bundle.AddFiles( + "/scripts/my-extension-script.js" + ); + }); + }); + } +} +```` ## Bundle Contributors diff --git a/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md b/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md index 6a229714c1..dd688f256c 100644 --- a/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md +++ b/docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md @@ -167,7 +167,27 @@ public class MyWebExtensionModule : AbpModule } ```` -> 无法通过代码配置未命名的bundle tag helpers, 因为它们的名称在开发时是未知的. 建议始终使用bundle tag helper的名称. +你也可以使用 `ConfigureAll` 方法配置所有现有的捆绑包: + +````C# +[DependsOn(typeof(MyWebModule))] +public class MyWebExtensionModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options + .ScriptBundles + .ConfigureAll(bundle => { + bundle.AddFiles( + "/scripts/my-extension-script.js" + ); + }); + }); + } +} +```` ### Bundle 贡献者 diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs index afc4ec6a4a..acb2ae9fac 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs @@ -9,11 +9,13 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling { private readonly ConcurrentDictionary _bundles; private readonly ConcurrentDictionary>> _lazyBundleConfigurationActions; + private readonly List> _lazyAllBundleConfigurationActions; public BundleConfigurationCollection() { _bundles = new ConcurrentDictionary(); _lazyBundleConfigurationActions = new ConcurrentDictionary>>(); + _lazyAllBundleConfigurationActions = new List>(); } /// @@ -90,6 +92,12 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling } } + lock (_lazyAllBundleConfigurationActions) + { + _lazyAllBundleConfigurationActions.ForEach(c => c.Invoke(bundle)); + } + + return bundle; } @@ -123,6 +131,29 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling return this; } + /// + /// Configures all bundles. + /// This method also works for lazy bundles (those are created using razor tag helpers). + /// + /// Configure action + /// Returns this object for chained calls. + public BundleConfigurationCollection ConfigureAll([NotNull] Action configureAction) + { + Check.NotNull(configureAction, nameof(configureAction)); + + foreach (var bundle in _bundles) + { + configureAction.Invoke(bundle.Value); + } + + lock (_lazyAllBundleConfigurationActions) + { + _lazyAllBundleConfigurationActions.Add(configureAction); + } + + return this; + } + /// /// Gets a bundle. /// @@ -140,4 +171,4 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling return bundle; } } -} \ No newline at end of file +}