diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfiguration.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfiguration.cs index 739104537e..c5a788c6a8 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfiguration.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfiguration.cs @@ -1,4 +1,6 @@ -namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling +using System.Collections.Generic; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling { public class BundleConfiguration { @@ -6,10 +8,14 @@ public BundleContributorCollection Contributors { get; } + public List BaseBundles { get; } + public BundleConfiguration(string name) { Name = name; + Contributors = new BundleContributorCollection(); + BaseBundles = new List(); } } } \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationContext.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationContext.cs index 31edaa97c1..735ce70492 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationContext.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationContext.cs @@ -1,19 +1,16 @@ using System; using System.Collections.Generic; -using Volo.Abp.AspNetCore.Mvc.UI.Theming; namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling { public class BundleConfigurationContext : IBundleConfigurationContext { public List Files { get; } - public ITheme Theme { get; } public IServiceProvider ServiceProvider { get; } - public BundleConfigurationContext(List files, ITheme theme, IServiceProvider serviceProvider) + public BundleConfigurationContext(IServiceProvider serviceProvider) { - Files = files; - Theme = theme; + Files = new List(); ServiceProvider = serviceProvider; } } diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleCollectionExtensions.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationExtensions.cs similarity index 54% rename from src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleCollectionExtensions.cs rename to src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationExtensions.cs index 7a79fa5941..227653bdc9 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleCollectionExtensions.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleConfigurationExtensions.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling { @@ -13,25 +12,32 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params IBundleContributor[] contributors) { - if (!contributors.IsNullOrEmpty()) + Check.NotNull(contributors, nameof(contributors)); + + foreach (var contributor in contributors) { - foreach (var contributor in contributors) - { - bundleConfiguration.Contributors.Add(contributor); - } + bundleConfiguration.Contributors.Add(contributor); } return bundleConfiguration; } + public static BundleConfiguration AddBaseBundles(this BundleConfiguration bundleConfiguration, params string[] bundleNames) + { + Check.NotNull(bundleNames, nameof(bundleNames)); + + bundleConfiguration.BaseBundles.AddRange(bundleNames); + + return bundleConfiguration; + } + public static BundleConfiguration AddContributors(this BundleConfiguration bundleConfiguration, params Type[] contributorTypes) { - if (!contributorTypes.IsNullOrEmpty()) + Check.NotNull(contributorTypes, nameof(contributorTypes)); + + foreach (var contributorType in contributorTypes) { - foreach (var contributorType in contributorTypes) - { - bundleConfiguration.Contributors.Add(contributorType); - } + bundleConfiguration.Contributors.Add(contributorType); } return bundleConfiguration; diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleManager.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleManager.cs index 0244da1107..f803c9d2f4 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleManager.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/BundleManager.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; @@ -46,27 +47,28 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling public List GetStyleBundleFiles(string bundleName) { - return GetBundleFiles(_options.StyleBundles.Get(bundleName), _styleBundler); + return GetBundleFiles(_options.StyleBundles, bundleName, _styleBundler); } public List GetScriptBundleFiles(string bundleName) { - return GetBundleFiles(_options.ScriptBundles.Get(bundleName), _scriptBundler); + return GetBundleFiles(_options.ScriptBundles, bundleName, _scriptBundler); } - protected virtual List GetBundleFiles(BundleConfiguration bundleConfiguration, IBundler bundler) + protected virtual List GetBundleFiles(BundleConfigurationCollection bundles, string bundleName, IBundler bundler) { //TODO: Caching //TODO: Concurrency - var files = CreateFileListFromConfiguration(bundleConfiguration); + + var files = CreateFileList(bundles, bundleName); if (!IsBundlingEnabled()) { return files; } - var bundleRelativePath = _options.BundleFolderName.EnsureEndsWith('/') + bundleConfiguration.Name + "." + bundler.FileExtension; + var bundleRelativePath = _options.BundleFolderName.EnsureEndsWith('/') + bundleName + "." + bundler.FileExtension; var bundleResult = bundler.Bundle(new BundlerContext(bundleRelativePath, files)); @@ -101,17 +103,16 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling //return !_hostingEnvironment.IsDevelopment(); } - protected virtual List CreateFileListFromConfiguration(BundleConfiguration bundleConfiguration) + protected virtual List CreateFileList(BundleConfigurationCollection bundles, string bundleName) { using (var scope = _serviceProvider.CreateScope()) { - var context = new BundleConfigurationContext( - new List(), - _themeManager.CurrentTheme, - scope.ServiceProvider - ); + var contributors = new List(); + var context = new BundleConfigurationContext(scope.ServiceProvider); + + AddContributorsWithBaseBundles(contributors, bundles, context, bundleName); - foreach (var contributor in bundleConfiguration.Contributors.GetAll()) + foreach (var contributor in contributors) { contributor.ConfigureBundle(context); } @@ -119,5 +120,22 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling return context.Files; } } + + protected virtual void AddContributorsWithBaseBundles(List contributors, BundleConfigurationCollection bundles, BundleConfigurationContext context, string bundleName) + { + var bundleConfiguration = bundles.Get(bundleName); + + foreach (var baseBundleName in bundleConfiguration.BaseBundles) + { + AddContributorsWithBaseBundles(contributors, bundles, context, baseBundleName); //Recursive call + } + + var selfContributors = bundleConfiguration.Contributors.GetAll(); + + if (selfContributors.Any()) + { + contributors.AddRange(selfContributors); + } + } } } \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleConfigurationContext.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleConfigurationContext.cs index 291e163a98..03c8ac13db 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleConfigurationContext.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Bundling/IBundleConfigurationContext.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Volo.Abp.AspNetCore.Mvc.UI.Theming; using Volo.Abp.DependencyInjection; namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling @@ -7,7 +6,5 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling public interface IBundleConfigurationContext : IServiceProviderAccessor { List Files { get; } - - ITheme Theme { get; } } } \ No newline at end of file