Browse Source

Merge pull request #7333 from abpframework/liangshiwei/bundle

Add ConfigureAll method to Bundle system
pull/7355/head
maliming 6 years ago
committed by GitHub
parent
commit
739a4f5f4b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      docs/en/UI/AspNetCore/Bundling-Minification.md
  2. 22
      docs/zh-Hans/UI/AspNetCore/Bundling-Minification.md
  3. 33
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleConfigurationCollection.cs

22
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<AbpBundlingOptions>(options =>
{
options
.ScriptBundles
.ConfigureAll(bundle => {
bundle.AddFiles(
"/scripts/my-extension-script.js"
);
});
});
}
}
````
## Bundle Contributors

22
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<AbpBundlingOptions>(options =>
{
options
.ScriptBundles
.ConfigureAll(bundle => {
bundle.AddFiles(
"/scripts/my-extension-script.js"
);
});
});
}
}
````
### Bundle 贡献者

33
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<string, BundleConfiguration> _bundles;
private readonly ConcurrentDictionary<string, List<Action<BundleConfiguration>>> _lazyBundleConfigurationActions;
private readonly List<Action<BundleConfiguration>> _lazyAllBundleConfigurationActions;
public BundleConfigurationCollection()
{
_bundles = new ConcurrentDictionary<string, BundleConfiguration>();
_lazyBundleConfigurationActions = new ConcurrentDictionary<string, List<Action<BundleConfiguration>>>();
_lazyAllBundleConfigurationActions = new List<Action<BundleConfiguration>>();
}
/// <summary>
@ -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;
}
/// <summary>
/// Configures all bundles.
/// This method also works for lazy bundles (those are created using razor tag helpers).
/// </summary>
/// <param name="configureAction">Configure action</param>
/// <returns>Returns this object for chained calls.</returns>
public BundleConfigurationCollection ConfigureAll([NotNull] Action<BundleConfiguration> configureAction)
{
Check.NotNull(configureAction, nameof(configureAction));
foreach (var bundle in _bundles)
{
configureAction.Invoke(bundle.Value);
}
lock (_lazyAllBundleConfigurationActions)
{
_lazyAllBundleConfigurationActions.Add(configureAction);
}
return this;
}
/// <summary>
/// Gets a bundle.
/// </summary>
@ -140,4 +171,4 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
return bundle;
}
}
}
}

Loading…
Cancel
Save