Browse Source

Resolved #8163: Allow to ignore files on minification (MVC UI).

pull/8170/head
Halil İbrahim Kalkan 5 years ago
parent
commit
925694f72b
  1. 9
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling.Abstractions/Volo/Abp/AspNetCore/Mvc/UI/Bundling/AbpBundlingOptions.cs
  2. 22
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundlerBase.cs
  3. 11
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Scripts/ScriptBundler.cs
  4. 11
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Styles/StyleBundler.cs
  5. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs

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

@ -1,12 +1,14 @@
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{
public class AbpBundlingOptions
{
public BundleConfigurationCollection StyleBundles { get; set; }
public BundleConfigurationCollection StyleBundles { get; }
public BundleConfigurationCollection ScriptBundles { get; set; }
public BundleConfigurationCollection ScriptBundles { get; }
//TODO: Add option to enable/disable bundling / minification
public HashSet<string> MinificationIgnoredFiles { get; }
/// <summary>
/// Default: "__bundles".
@ -22,6 +24,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{
StyleBundles = new BundleConfigurationCollection();
ScriptBundles = new BundleConfigurationCollection();
MinificationIgnoredFiles = new HashSet<string>();
}
}
}

22
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundlerBase.cs

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Minify;
@ -18,11 +19,16 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
protected IWebHostEnvironment HostEnvironment { get; }
protected IMinifier Minifier { get; }
protected AbpBundlingOptions BundlingOptions { get; }
protected BundlerBase(IWebHostEnvironment hostEnvironment, IMinifier minifier)
protected BundlerBase(
IWebHostEnvironment hostEnvironment,
IMinifier minifier,
IOptions<AbpBundlingOptions> bundlingOptions)
{
HostEnvironment = hostEnvironment;
Minifier = minifier;
BundlingOptions = bundlingOptions.Value;
Logger = NullLogger<BundlerBase>.Instance;
}
@ -56,14 +62,22 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
private string GetFileContentConsideringMinification(IBundlerContext context, string fileName)
{
var isIgnoredForMinification = BundlingOptions.MinificationIgnoredFiles.Contains(fileName);
var isMinFile = IsMinFile(fileName);
if (!context.IsMinificationEnabled || isMinFile)
if (!context.IsMinificationEnabled || isIgnoredForMinification || isMinFile)
{
var fileContent = GetFileInfo(context, fileName).ReadAsString();
Logger.LogDebug($"- {fileName} ({fileContent.Length} bytes)");
if (context.IsMinificationEnabled && isMinFile)
if (context.IsMinificationEnabled)
{
Logger.LogDebug(" > Already minified");
if (isMinFile)
{
Logger.LogDebug(" > Already minified.");
}
else if (isIgnoredForMinification)
{
Logger.LogDebug(" > Ignored for minification.");
}
}
return fileContent;

11
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Scripts/ScriptBundler.cs

@ -1,5 +1,6 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem;
using Volo.Abp.Minify.Scripts;
@ -9,8 +10,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Scripts
{
public override string FileExtension => "js";
public ScriptBundler(IWebHostEnvironment hostEnvironment, IJavascriptMinifier minifier)
: base(hostEnvironment, minifier)
public ScriptBundler(
IWebHostEnvironment hostEnvironment,
IJavascriptMinifier minifier,
IOptions<AbpBundlingOptions> bundlingOptions)
: base(
hostEnvironment,
minifier,
bundlingOptions)
{
}

11
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Styles/StyleBundler.cs

@ -1,6 +1,7 @@
using System;
using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem;
using Volo.Abp.Minify.Styles;
@ -11,8 +12,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Styles
private readonly IWebHostEnvironment _hostingEnvironment;
public override string FileExtension => "css";
public StyleBundler(IWebHostEnvironment hostEnvironment, ICssMinifier minifier)
: base(hostEnvironment, minifier)
public StyleBundler(
IWebHostEnvironment hostEnvironment,
ICssMinifier minifier,
IOptions<AbpBundlingOptions> bundlingOptions)
: base(
hostEnvironment,
minifier,
bundlingOptions)
{
_hostingEnvironment = hostEnvironment;
}

2
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpTagHelperResourceService.cs

@ -20,7 +20,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
public ILogger<AbpTagHelperResourceService> Logger { get; set; }
protected IBundleManager BundleManager { get; }
protected IWebHostEnvironment HostingEnvironment { get; }
protected readonly AbpBundlingOptions Options;
protected AbpBundlingOptions Options { get; }
protected AbpTagHelperResourceService(
IBundleManager bundleManager,

Loading…
Cancel
Save