maliming
4 years ago
No known key found for this signature in database
GPG Key ID: 96224957E51C89E
4 changed files with
17 additions and
37 deletions
-
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpBundlingOptions.cs
-
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptService.cs
-
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperScriptStyleLoadingOptions.cs
-
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperStyleService.cs
|
|
|
@ -20,11 +20,23 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|
|
|
/// </summary>
|
|
|
|
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() |
|
|
|
{ |
|
|
|
StyleBundles = new BundleConfigurationCollection(); |
|
|
|
ScriptBundles = new BundleConfigurationCollection(); |
|
|
|
MinificationIgnoredFiles = new HashSet<string>(); |
|
|
|
DeferScriptsByDefault = false; |
|
|
|
DeferScripts = new List<string>(); |
|
|
|
PreloadStylesByDefault = false; |
|
|
|
PreloadStyles = new List<string>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -13,18 +13,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|
|
|
{ |
|
|
|
public class AbpTagHelperScriptService : AbpTagHelperResourceService |
|
|
|
{ |
|
|
|
protected AbpTagHelperScriptStyleLoadingOptions LoadingOptions { get; } |
|
|
|
|
|
|
|
public AbpTagHelperScriptService( |
|
|
|
IBundleManager bundleManager, |
|
|
|
IOptions<AbpBundlingOptions> options, |
|
|
|
IWebHostEnvironment hostingEnvironment, |
|
|
|
IOptions<AbpTagHelperScriptStyleLoadingOptions> loadingOptions) : base( |
|
|
|
IWebHostEnvironment hostingEnvironment) : base( |
|
|
|
bundleManager, |
|
|
|
options, |
|
|
|
hostingEnvironment) |
|
|
|
{ |
|
|
|
LoadingOptions = loadingOptions.Value; |
|
|
|
} |
|
|
|
|
|
|
|
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) |
|
|
|
@ -50,7 +46,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|
|
|
_ => 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" |
|
|
|
: string.Empty; |
|
|
|
output.Content.AppendHtml($"<script {deferText} src=\"{viewContext.GetUrlHelper().Content(file.EnsureStartsWith('~'))}\"></script>{Environment.NewLine}"); |
|
|
|
|
|
|
|
@ -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>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -13,18 +13,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|
|
|
{ |
|
|
|
public class AbpTagHelperStyleService : AbpTagHelperResourceService |
|
|
|
{ |
|
|
|
protected AbpTagHelperScriptStyleLoadingOptions LoadingOptions { get; } |
|
|
|
|
|
|
|
public AbpTagHelperStyleService( |
|
|
|
IBundleManager bundleManager, |
|
|
|
IOptions<AbpBundlingOptions> options, |
|
|
|
IWebHostEnvironment hostingEnvironment, |
|
|
|
IOptions<AbpTagHelperScriptStyleLoadingOptions> loadingOptions) : base( |
|
|
|
IWebHostEnvironment hostingEnvironment) : base( |
|
|
|
bundleManager, |
|
|
|
options, |
|
|
|
hostingEnvironment) |
|
|
|
{ |
|
|
|
LoadingOptions = loadingOptions.Value; |
|
|
|
} |
|
|
|
|
|
|
|
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) |
|
|
|
@ -50,7 +46,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|
|
|
_ => 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}"); |
|
|
|
} |
|
|
|
|