From dec0b6ffa557607b951b3d733c0826c6242cec16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 4 Sep 2019 16:42:59 +0300 Subject: [PATCH] Fix url paths in also minified css files. --- .../AspNetCore/Mvc/UI/Bundling/BundlerBase.cs | 31 +++++++++++-------- .../Mvc/UI/Bundling/Scripts/ScriptBundler.cs | 4 +-- .../Mvc/UI/Bundling/Styles/StyleBundler.cs | 16 +++++----- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundlerBase.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundlerBase.cs index 90e8606833..8c2258e1eb 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundlerBase.cs +++ b/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) { + string fileContent = null; + if (context.IsMinificationEnabled && !IsMinFile(fileName)) { var minFileInfo = GetMinFileInfoOrNull(fileName); if (minFileInfo != null) { - Logger.LogDebug($"- {fileName} ({minFileInfo.Length} bytes)"); - bundleContentBuilder.Append(NormalizedCode(minFileInfo.ReadAsString())); - return; + Logger.LogDebug($"- {fileName} ({minFileInfo.Length} bytes) - already minified"); + fileContent = minFileInfo.ReadAsString(); } } - var fileContent = GetFileContent(context, fileName); - Logger.LogDebug($"- {fileName} ({fileContent.Length} bytes)"); - - if (context.IsMinificationEnabled) + if (fileContent == null) { - var nonMinifiedSize = fileContent.Length; - fileContent = Minifier.Minify(fileContent, context.BundleRelativePath); - Logger.LogInformation($" -- Minified {context.BundleRelativePath} ({nonMinifiedSize} bytes -> {fileContent.Length} bytes)"); + fileContent = GetFileContent(context, fileName); + Logger.LogDebug($"- {fileName} ({fileContent.Length} bytes) - non minified"); + + 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) @@ -99,9 +104,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling 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; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Scripts/ScriptBundler.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Scripts/ScriptBundler.cs index f5447dc8a3..7b2887eb90 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Scripts/ScriptBundler.cs +++ b/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; } } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Styles/StyleBundler.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Styles/StyleBundler.cs index 768a1bb136..31c3f1dacf 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/Styles/StyleBundler.cs +++ b/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; } - protected override string GetFileContent(IBundlerContext context, string file) + public string GetAbsolutePath(string relativePath) { - return CssRelativePath.Adjust( - base.GetFileContent(context, file), - GetAbsolutePath(file), - GetAbsolutePath(context.BundleRelativePath) - ); + return Path.Combine(_hostingEnvironment.ContentRootPath, "wwwroot", relativePath.RemovePreFix("/")); } - 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) + ); } } } \ No newline at end of file