Browse Source

Merge branch 'dev' of https://github.com/abpframework/abp into dev

pull/1718/head
Armağan Ünlü 7 years ago
parent
commit
b1c43c0f16
  1. 31
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundlerBase.cs
  2. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Scripts/ScriptBundler.cs
  3. 16
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Styles/StyleBundler.cs

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

@ -46,28 +46,33 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
private void AddFileToBundle(IBundlerContext context, StringBuilder bundleContentBuilder, string fileName) private void AddFileToBundle(IBundlerContext context, StringBuilder bundleContentBuilder, string fileName)
{ {
string fileContent = null;
if (context.IsMinificationEnabled && !IsMinFile(fileName)) if (context.IsMinificationEnabled && !IsMinFile(fileName))
{ {
var minFileInfo = GetMinFileInfoOrNull(fileName); var minFileInfo = GetMinFileInfoOrNull(fileName);
if (minFileInfo != null) if (minFileInfo != null)
{ {
Logger.LogDebug($"- {fileName} ({minFileInfo.Length} bytes)"); Logger.LogDebug($"- {fileName} ({minFileInfo.Length} bytes) - already minified");
bundleContentBuilder.Append(NormalizedCode(minFileInfo.ReadAsString())); fileContent = minFileInfo.ReadAsString();
return;
} }
} }
var fileContent = GetFileContent(context, fileName); if (fileContent == null)
Logger.LogDebug($"- {fileName} ({fileContent.Length} bytes)");
if (context.IsMinificationEnabled)
{ {
var nonMinifiedSize = fileContent.Length; fileContent = GetFileContent(context, fileName);
fileContent = Minifier.Minify(fileContent, context.BundleRelativePath); Logger.LogDebug($"- {fileName} ({fileContent.Length} bytes) - non minified");
Logger.LogInformation($" -- Minified {context.BundleRelativePath} ({nonMinifiedSize} bytes -> {fileContent.Length} bytes)");
if (context.IsMinificationEnabled)
{
var nonMinifiedSize = fileContent.Length;
fileContent = Minifier.Minify(fileContent, context.BundleRelativePath);
Logger.LogInformation($" > Minified {fileName} ({nonMinifiedSize} bytes -> {fileContent.Length} bytes)");
}
} }
bundleContentBuilder.Append(NormalizedCode(fileContent)); fileContent = ProcessBeforeAddingToTheBundle(context, fileName, fileContent);
bundleContentBuilder.Append(fileContent);
} }
protected virtual string GetFileContent(IBundlerContext context, string file) protected virtual string GetFileContent(IBundlerContext context, string file)
@ -99,9 +104,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
return fileInfo.Exists ? fileInfo : null; return fileInfo.Exists ? fileInfo : null;
} }
protected virtual string NormalizedCode(string code) protected virtual string ProcessBeforeAddingToTheBundle(IBundlerContext context, string filePath, string fileContent)
{ {
return code; return fileContent;
} }
} }
} }

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

@ -13,9 +13,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Scripts
{ {
} }
protected override string NormalizedCode(string code) protected override string ProcessBeforeAddingToTheBundle(IBundlerContext context, string filePath, string fileContent)
{ {
return code.EnsureEndsWith(';') + Environment.NewLine; return fileContent.EnsureEndsWith(';') + Environment.NewLine;
} }
} }
} }

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

@ -17,18 +17,18 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.Styles
_hostingEnvironment = hostingEnvironment; _hostingEnvironment = hostingEnvironment;
} }
protected override string GetFileContent(IBundlerContext context, string file) public string GetAbsolutePath(string relativePath)
{ {
return CssRelativePath.Adjust( return Path.Combine(_hostingEnvironment.ContentRootPath, "wwwroot", relativePath.RemovePreFix("/"));
base.GetFileContent(context, file),
GetAbsolutePath(file),
GetAbsolutePath(context.BundleRelativePath)
);
} }
public string GetAbsolutePath(string relativePath) protected override string ProcessBeforeAddingToTheBundle(IBundlerContext context, string filePath, string fileContent)
{ {
return Path.Combine(_hostingEnvironment.ContentRootPath, "wwwroot", relativePath.RemovePreFix("/")); return CssRelativePath.Adjust(
fileContent,
GetAbsolutePath(filePath),
GetAbsolutePath(context.BundleRelativePath)
);
} }
} }
} }
Loading…
Cancel
Save