Browse Source

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

pull/8170/head
Halil İbrahim Kalkan 6 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 namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{ {
public class AbpBundlingOptions 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> /// <summary>
/// Default: "__bundles". /// Default: "__bundles".
@ -22,6 +24,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
{ {
StyleBundles = new BundleConfigurationCollection(); StyleBundles = new BundleConfigurationCollection();
ScriptBundles = 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.FileProviders;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem; using Volo.Abp.AspNetCore.VirtualFileSystem;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Minify; using Volo.Abp.Minify;
@ -18,11 +19,16 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
protected IWebHostEnvironment HostEnvironment { get; } protected IWebHostEnvironment HostEnvironment { get; }
protected IMinifier Minifier { 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; HostEnvironment = hostEnvironment;
Minifier = minifier; Minifier = minifier;
BundlingOptions = bundlingOptions.Value;
Logger = NullLogger<BundlerBase>.Instance; Logger = NullLogger<BundlerBase>.Instance;
} }
@ -56,14 +62,22 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
private string GetFileContentConsideringMinification(IBundlerContext context, string fileName) private string GetFileContentConsideringMinification(IBundlerContext context, string fileName)
{ {
var isIgnoredForMinification = BundlingOptions.MinificationIgnoredFiles.Contains(fileName);
var isMinFile = IsMinFile(fileName); var isMinFile = IsMinFile(fileName);
if (!context.IsMinificationEnabled || isMinFile) if (!context.IsMinificationEnabled || isIgnoredForMinification || isMinFile)
{ {
var fileContent = GetFileInfo(context, fileName).ReadAsString(); var fileContent = GetFileInfo(context, fileName).ReadAsString();
Logger.LogDebug($"- {fileName} ({fileContent.Length} bytes)"); 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; 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 System;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem; using Volo.Abp.AspNetCore.VirtualFileSystem;
using Volo.Abp.Minify.Scripts; using Volo.Abp.Minify.Scripts;
@ -9,8 +10,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Scripts
{ {
public override string FileExtension => "js"; public override string FileExtension => "js";
public ScriptBundler(IWebHostEnvironment hostEnvironment, IJavascriptMinifier minifier) public ScriptBundler(
: base(hostEnvironment, minifier) 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;
using System.IO; using System.IO;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem; using Volo.Abp.AspNetCore.VirtualFileSystem;
using Volo.Abp.Minify.Styles; using Volo.Abp.Minify.Styles;
@ -11,8 +12,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Styles
private readonly IWebHostEnvironment _hostingEnvironment; private readonly IWebHostEnvironment _hostingEnvironment;
public override string FileExtension => "css"; public override string FileExtension => "css";
public StyleBundler(IWebHostEnvironment hostEnvironment, ICssMinifier minifier) public StyleBundler(
: base(hostEnvironment, minifier) IWebHostEnvironment hostEnvironment,
ICssMinifier minifier,
IOptions<AbpBundlingOptions> bundlingOptions)
: base(
hostEnvironment,
minifier,
bundlingOptions)
{ {
_hostingEnvironment = hostEnvironment; _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; } public ILogger<AbpTagHelperResourceService> Logger { get; set; }
protected IBundleManager BundleManager { get; } protected IBundleManager BundleManager { get; }
protected IWebHostEnvironment HostingEnvironment { get; } protected IWebHostEnvironment HostingEnvironment { get; }
protected readonly AbpBundlingOptions Options; protected AbpBundlingOptions Options { get; }
protected AbpTagHelperResourceService( protected AbpTagHelperResourceService(
IBundleManager bundleManager, IBundleManager bundleManager,

Loading…
Cancel
Save