Browse Source

Refactor.

pull/10317/head
maliming 5 years ago
parent
commit
7daaeeb765
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 14
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpBundlingOptions.cs
  2. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs
  3. 24
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptStyleLoadingOptions.cs
  4. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs

14
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpBundlingOptions.cs

@ -20,11 +20,23 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
/// </summary> /// </summary>
public BundlingMode Mode { get; set; } = BundlingMode.Auto; public BundlingMode Mode { get; set; } = BundlingMode.Auto;
public bool DeferScriptsByDefault { get; set; }
public List<string> DeferScripts { get; }
public bool PreloadStylesByDefault { get; set; }
public List<string> PreloadStyles { get; }
public AbpBundlingOptions() public AbpBundlingOptions()
{ {
StyleBundles = new BundleConfigurationCollection(); StyleBundles = new BundleConfigurationCollection();
ScriptBundles = new BundleConfigurationCollection(); ScriptBundles = new BundleConfigurationCollection();
MinificationIgnoredFiles = new HashSet<string>(); MinificationIgnoredFiles = new HashSet<string>();
DeferScriptsByDefault = false;
DeferScripts = new List<string>();
PreloadStylesByDefault = false;
PreloadStyles = new List<string>();
} }
} }
} }

8
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs

@ -13,18 +13,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
{ {
public class AbpTagHelperScriptService : AbpTagHelperResourceService public class AbpTagHelperScriptService : AbpTagHelperResourceService
{ {
protected AbpTagHelperScriptStyleLoadingOptions LoadingOptions { get; }
public AbpTagHelperScriptService( public AbpTagHelperScriptService(
IBundleManager bundleManager, IBundleManager bundleManager,
IOptions<AbpBundlingOptions> options, IOptions<AbpBundlingOptions> options,
IWebHostEnvironment hostingEnvironment, IWebHostEnvironment hostingEnvironment) : base(
IOptions<AbpTagHelperScriptStyleLoadingOptions> loadingOptions) : base(
bundleManager, bundleManager,
options, options,
hostingEnvironment) hostingEnvironment)
{ {
LoadingOptions = loadingOptions.Value;
} }
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems)
@ -50,7 +46,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
_ => false _ => false
}; };
var deferText = (defer || LoadingOptions.GlobalDeferScript || LoadingOptions.DeferScripts.Any(x => file.StartsWith(x, StringComparison.OrdinalIgnoreCase))) var deferText = (defer || Options.DeferScriptsByDefault || Options.DeferScripts.Any(x => file.StartsWith(x, StringComparison.OrdinalIgnoreCase)))
? "defer" ? "defer"
: string.Empty; : string.Empty;
output.Content.AppendHtml($"<script {deferText} src=\"{viewContext.GetUrlHelper().Content(file.EnsureStartsWith('~'))}\"></script>{Environment.NewLine}"); output.Content.AppendHtml($"<script {deferText} src=\"{viewContext.GetUrlHelper().Content(file.EnsureStartsWith('~'))}\"></script>{Environment.NewLine}");

24
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptStyleLoadingOptions.cs

@ -1,24 +0,0 @@
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
{
public class AbpTagHelperScriptStyleLoadingOptions
{
public bool GlobalDeferScript { get; set; }
public List<string> DeferScripts { get; }
public bool GlobalPreloadStyle { get; set; }
public List<string> PreloadStyles { get; }
public AbpTagHelperScriptStyleLoadingOptions()
{
GlobalDeferScript = false;
DeferScripts = new List<string>();
GlobalPreloadStyle = false;
PreloadStyles = new List<string>();
}
}
}

8
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs

@ -13,18 +13,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
{ {
public class AbpTagHelperStyleService : AbpTagHelperResourceService public class AbpTagHelperStyleService : AbpTagHelperResourceService
{ {
protected AbpTagHelperScriptStyleLoadingOptions LoadingOptions { get; }
public AbpTagHelperStyleService( public AbpTagHelperStyleService(
IBundleManager bundleManager, IBundleManager bundleManager,
IOptions<AbpBundlingOptions> options, IOptions<AbpBundlingOptions> options,
IWebHostEnvironment hostingEnvironment, IWebHostEnvironment hostingEnvironment) : base(
IOptions<AbpTagHelperScriptStyleLoadingOptions> loadingOptions) : base(
bundleManager, bundleManager,
options, options,
hostingEnvironment) hostingEnvironment)
{ {
LoadingOptions = loadingOptions.Value;
} }
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems)
@ -50,7 +46,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
_ => false _ => false
}; };
if (preload || LoadingOptions.GlobalPreloadStyle || LoadingOptions.PreloadStyles.Any(x => file.StartsWith(x, StringComparison.OrdinalIgnoreCase))) if (preload || Options.PreloadStylesByDefault || Options.PreloadStyles.Any(x => file.StartsWith(x, StringComparison.OrdinalIgnoreCase)))
{ {
output.Content.AppendHtml($"<link rel=\"preload\" href=\"{viewContext.GetUrlHelper().Content(file.EnsureStartsWith('~'))}\" as=\"style\" onload=\"this.rel='stylesheet'\" />{Environment.NewLine}"); output.Content.AppendHtml($"<link rel=\"preload\" href=\"{viewContext.GetUrlHelper().Content(file.EnsureStartsWith('~'))}\" as=\"style\" onload=\"this.rel='stylesheet'\" />{Environment.NewLine}");
} }

Loading…
Cancel
Save