|
|
@ -1,3 +1,4 @@ |
|
|
|
|
|
using System; |
|
|
using System.Text; |
|
|
using System.Text; |
|
|
using Microsoft.Extensions.FileProviders; |
|
|
using Microsoft.Extensions.FileProviders; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
@ -34,19 +35,38 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|
|
Logger.LogDebug("Bundle files:"); |
|
|
Logger.LogDebug("Bundle files:"); |
|
|
foreach (var file in context.ContentFiles) |
|
|
foreach (var file in context.ContentFiles) |
|
|
{ |
|
|
{ |
|
|
var fileContent = GetFileContent(context, file); |
|
|
var fileInfo = GetFileInfo(context, file); |
|
|
Logger.LogDebug($"- {file} ({fileContent.Length} bytes)"); |
|
|
var fileContent = fileInfo.ReadAsString(); |
|
|
sb.AppendLine(fileContent); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var bundleContent = sb.ToString(); |
|
|
Logger.LogDebug($"- {file} ({fileContent.Length} bytes)"); |
|
|
|
|
|
|
|
|
if (context.IsMinificationEnabled) |
|
|
if (IsMinFile(fileInfo)) |
|
|
{ |
|
|
{ |
|
|
Logger.LogInformation($"Minifying {context.BundleRelativePath} ({bundleContent.Length} bytes)"); |
|
|
sb.Append(NormalizedCode(fileContent)); |
|
|
bundleContent = Minifier.Minify(bundleContent, context.BundleRelativePath); |
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
var minFileContent = GetMinFileOrNull(file); |
|
|
|
|
|
if (minFileContent != null) |
|
|
|
|
|
{ |
|
|
|
|
|
sb.Append(NormalizedCode(minFileContent)); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
if (context.IsMinificationEnabled) |
|
|
|
|
|
{ |
|
|
|
|
|
Logger.LogInformation($"Minifying {context.BundleRelativePath} ({fileInfo.Length} bytes)"); |
|
|
|
|
|
sb.Append(NormalizedCode(Minifier.Minify(fileContent, context.BundleRelativePath))); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
sb.Append(NormalizedCode(fileContent)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var bundleContent = sb.ToString(); |
|
|
Logger.LogInformation($"Bundled {context.BundleRelativePath} ({bundleContent.Length} bytes)"); |
|
|
Logger.LogInformation($"Bundled {context.BundleRelativePath} ({bundleContent.Length} bytes)"); |
|
|
|
|
|
|
|
|
return new BundleResult(bundleContent); |
|
|
return new BundleResult(bundleContent); |
|
|
@ -68,5 +88,23 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling |
|
|
|
|
|
|
|
|
return fileInfo; |
|
|
return fileInfo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual bool IsMinFile(IFileInfo fileInfo) |
|
|
|
|
|
{ |
|
|
|
|
|
return fileInfo.Name.EndsWith($".min.{FileExtension}", StringComparison.InvariantCultureIgnoreCase); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual string GetMinFileOrNull(string file) |
|
|
|
|
|
{ |
|
|
|
|
|
var fileInfo = |
|
|
|
|
|
WebContentFileProvider.GetFileInfo($"{file.RemovePostFix($".{FileExtension}")}.min.{FileExtension}"); |
|
|
|
|
|
|
|
|
|
|
|
return fileInfo.Exists ? fileInfo.ReadAsString() : null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected virtual string NormalizedCode(string code) |
|
|
|
|
|
{ |
|
|
|
|
|
return code; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |