Browse Source

Merge pull request #10458 from abpframework/maliming/minify

Use the original file content when an error occurs.
pull/10500/head
Halil İbrahim Kalkan 5 years ago
committed by GitHub
parent
commit
d89ae66b33
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundlerBase.cs
  2. 9
      framework/src/Volo.Abp.Minify/Volo/Abp/Minify/NUglify/NUglifyException.cs
  3. 22
      framework/src/Volo.Abp.Minify/Volo/Abp/Minify/NUglify/NUglifyMinifierBase.cs

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

@ -5,7 +5,6 @@ using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.VirtualFileSystem;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Minify;
@ -102,13 +101,22 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
Logger.LogDebug($"- {fileName} ({nonMinifiedSize} bytes) - non minified, minifying...");
fileContent = Minifier.Minify(
fileContent,
context.BundleRelativePath,
fileName
);
try
{
fileContent = Minifier.Minify(
fileContent,
context.BundleRelativePath,
fileName
);
Logger.LogInformation($" > Minified {fileName} ({nonMinifiedSize} bytes -> {fileContent.Length} bytes)");
Logger.LogInformation($" > Minified {fileName} ({nonMinifiedSize} bytes -> {fileContent.Length} bytes)");
return fileContent;
}
catch (Exception ex)
{
Logger.LogWarning($"Unable to minify the file: {fileName}. Return file content without minification.", ex);
}
return fileContent;
}

9
framework/src/Volo.Abp.Minify/Volo/Abp/Minify/NUglify/NUglifyException.cs

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using NUglify;
@ -14,6 +15,12 @@ namespace Volo.Abp.Minify.NUglify
Errors = errors;
}
public NUglifyException(string message, Exception innerException)
: base(message, innerException)
{
}
/// <summary>
/// Constructor for serializing.
/// </summary>
@ -23,4 +30,4 @@ namespace Volo.Abp.Minify.NUglify
}
}
}
}

22
framework/src/Volo.Abp.Minify/Volo/Abp/Minify/NUglify/NUglifyMinifierBase.cs

@ -31,11 +31,25 @@ namespace Volo.Abp.Minify.NUglify
string fileName = null,
string originalFileName = null)
{
var result = UglifySource(source, fileName);
CheckErrors(result, originalFileName);
return result.Code;
try
{
var result = UglifySource(source, fileName);
CheckErrors(result, originalFileName);
return result.Code;
}
catch (Exception e)
{
var errorMessage = "There is an error in uglifying the given source code!";
if (originalFileName != null)
{
errorMessage += " Original file: " + originalFileName;
}
throw new NUglifyException($"{errorMessage}{Environment.NewLine}{e.Message}", e);
}
}
protected abstract UglifyResult UglifySource(string source, string fileName);
}
}
}

Loading…
Cancel
Save