Fix url paths in also minified css files.

pull/1718/head
Halil İbrahim Kalkan 5 years ago
parent 373fd299c3
commit dec0b6ffa5

@ -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;
}
}
}

@ -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;
}
}
}

@ -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)
);
}
}
}
Loading…
Cancel
Save