private string GetFileContentConsideringMinification(IBundlerContext context, string fileName) { var isMinFile = IsMinFile(fileName); if (!context.IsMinificationEnabled || isMinFile) { var fileContent = GetFileInfo(context, fileName).ReadAsString(); Logger.LogDebug($"- {fileName} ({fileContent.Length} bytes)"); if (context.IsMinificationEnabled && isMinFile) { Logger.LogDebug(" > Already minified"); } return(fileContent); } var minFileInfo = GetMinFileInfoOrNull(fileName); if (minFileInfo != null) { var fileContent = minFileInfo.ReadAsString(); Logger.LogDebug($"- {fileName}"); Logger.LogDebug($" > Using the pre-minified file: {minFileInfo.Name} ({fileContent.Length} bytes)"); return(fileContent); } return(GetAndMinifyFileContent(context, fileName)); }
private string GetAndMinifyFileContent(IBundlerContext context, string fileName) { var fileContent = GetFileInfo(context, fileName).ReadAsString(); var nonMinifiedSize = fileContent.Length; Logger.LogDebug($"- {fileName} ({nonMinifiedSize} bytes) - non minified, minifying..."); try { fileContent = Minifier.Minify( fileContent, context.BundleRelativePath, fileName ); 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); }
private void AddFileToBundle(IBundlerContext context, StringBuilder bundleContentBuilder, string fileName) { var fileContent = GetFileContentConsideringMinification(context, fileName); fileContent = ProcessBeforeAddingToTheBundle(context, fileName, fileContent); bundleContentBuilder.Append(fileContent); }
public BundleResult Bundle(IBundlerContext context) { Logger.LogInformation($"Bundling {context.BundleRelativePath} ({context.ContentFiles.Count} files)"); var sb = new StringBuilder(); Logger.LogDebug("Bundle files:"); foreach (var file in context.ContentFiles) { var fileContent = GetFileContent(context, file); Logger.LogDebug($"- {file} ({fileContent.Length} bytes)"); sb.AppendLine(fileContent); } var bundleContent = sb.ToString(); if (context.IsMinificationEnabled) { Logger.LogInformation($"Minifying {context.BundleRelativePath} ({bundleContent.Length} bytes)"); bundleContent = Minifier.Minify(bundleContent, context.BundleRelativePath); } Logger.LogInformation($"Bundled {context.BundleRelativePath} ({bundleContent.Length} bytes)"); return(new BundleResult(bundleContent)); }
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) - already minified"); fileContent = minFileInfo.ReadAsString(); } } if (fileContent == null) { 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)"); } } fileContent = ProcessBeforeAddingToTheBundle(context, fileName, fileContent); bundleContentBuilder.Append(fileContent); }
private void AddFileToBundle(IBundlerContext context, StringBuilder bundleContentBuilder, string fileName) { if (context.IsMinificationEnabled && !IsMinFile(fileName)) { var minFileInfo = GetMinFileInfoOrNull(fileName); if (minFileInfo != null) { Logger.LogDebug($"- {fileName} ({minFileInfo.Length} bytes)"); bundleContentBuilder.Append(NormalizedCode(minFileInfo.ReadAsString())); return; } } var fileContent = GetFileContent(context, fileName); Logger.LogDebug($"- {fileName} ({fileContent.Length} bytes)"); if (context.IsMinificationEnabled) { var nonMinifiedSize = fileContent.Length; fileContent = Minifier.Minify(fileContent, context.BundleRelativePath); Logger.LogInformation($" -- Minified {context.BundleRelativePath} ({nonMinifiedSize} bytes -> {fileContent.Length} bytes)"); } bundleContentBuilder.Append(NormalizedCode(fileContent)); }
protected override string ProcessBeforeAddingToTheBundle(IBundlerContext context, string filePath, string fileContent) { return(CssRelativePath.Adjust( fileContent, GetAbsolutePath(filePath), GetAbsolutePath(context.BundleRelativePath) )); }
protected override string GetFileContent(IBundlerContext context, string file) { return(CssRelativePath.Adjust( base.GetFileContent(context, file), GetAbsolutePath(file), GetAbsolutePath(context.BundleRelativePath) )); }
protected virtual IFileInfo GetFileInfo(IBundlerContext context, string file) { var fileInfo = WebContentFileProvider.GetFileInfo(file); if (!fileInfo.Exists) { throw new AbpException($"Could not find file '{file}' using {nameof(IWebContentFileProvider)}"); } return(fileInfo); }
protected virtual IFileInfo GetFileInfo(IBundlerContext context, string file) { var fileInfo = HostEnvironment.WebRootFileProvider.GetFileInfo(file); if (!fileInfo.Exists) { throw new AbpException($"Could not find file '{file}'"); } return(fileInfo); }
private string GetAndMinifyFileContent(IBundlerContext context, string fileName) { var fileContent = GetFileInfo(context, fileName).ReadAsString(); var nonMinifiedSize = fileContent.Length; Logger.LogDebug($"- {fileName} ({nonMinifiedSize} bytes) - non minified, minifying..."); fileContent = Minifier.Minify( fileContent, context.BundleRelativePath, fileName ); Logger.LogInformation($" > Minified {fileName} ({nonMinifiedSize} bytes -> {fileContent.Length} bytes)"); return(fileContent); }
public BundleResult Bundle(IBundlerContext context) { Logger.LogInformation($"Bundling {context.BundleRelativePath} ({context.ContentFiles.Count} files)"); var bundleContentBuilder = new StringBuilder(); Logger.LogDebug("Bundle files:"); foreach (var file in context.ContentFiles) { AddFileToBundle(context, bundleContentBuilder, file); } var bundleContent = bundleContentBuilder.ToString(); Logger.LogInformation($"Bundled {context.BundleRelativePath} ({bundleContent.Length} bytes)"); return(new BundleResult(bundleContent)); }
private string GetFileContentConsideringMinification(IBundlerContext context, string fileName) { var isIgnoredForMinification = BundlingOptions.MinificationIgnoredFiles.Contains(fileName); var isMinFile = IsMinFile(fileName); if (!context.IsMinificationEnabled || isIgnoredForMinification || isMinFile) { var fileContent = GetFileInfo(context, fileName).ReadAsString(); Logger.LogDebug($"- {fileName} ({fileContent.Length} bytes)"); if (context.IsMinificationEnabled) { if (isMinFile) { Logger.LogDebug(" > Already minified."); } else if (isIgnoredForMinification) { Logger.LogDebug(" > Ignored for minification."); } } return(fileContent); } var minFileInfo = GetMinFileInfoOrNull(fileName); if (minFileInfo != null) { var fileContent = minFileInfo.ReadAsString(); Logger.LogDebug($"- {fileName}"); Logger.LogDebug($" > Using the pre-minified file: {minFileInfo.Name} ({fileContent.Length} bytes)"); return(fileContent); } return(GetAndMinifyFileContent(context, fileName)); }
protected virtual string ProcessBeforeAddingToTheBundle(IBundlerContext context, string filePath, string fileContent) { return(fileContent); }
protected override string ProcessBeforeAddingToTheBundle(IBundlerContext context, string filePath, string fileContent) { return(fileContent.EnsureEndsWith(';') + Environment.NewLine); }
protected virtual string GetFileContent(IBundlerContext context, string file) { return(GetFileInfo(context, file).ReadAsString()); }