-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working Source Map emit for JavaScriptBundle (#311)
* Working Source Map emit for JavaScriptBundle * Cleanup JavascriptMinifierTests to use JsSettings instead of direct use of Nuglify's CodeSettings class
- Loading branch information
Showing
9 changed files
with
213 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using WebOptimizer; | ||
using WebOptimizer.Processors; | ||
|
||
namespace WebOptimizer.Processors | ||
{ | ||
internal class ItemContentEmitter : Processor | ||
{ | ||
public override Task ExecuteAsync(IAssetContext context) | ||
{ | ||
var asset = context.Asset; | ||
var items = asset.Items; | ||
if (!items.ContainsKey("Content")) | ||
return Task.CompletedTask; | ||
|
||
context.Content = new Dictionary<string, byte[]> | ||
{ | ||
{ "Content", ((string)items["Content"]).AsByteArray() } | ||
}; | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
|
||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static partial class AssetPipelineExtensions | ||
{ | ||
/// <summary> | ||
/// Changes the Asset to only emit to Response what is stored in | ||
/// asset.Items["Content"] | ||
/// and nothing else | ||
/// | ||
/// Useful for Generated Content | ||
/// | ||
/// Used by JavaScriptMinifier.AddJavaScriptBundle to emit sourcemaps into a separate Asset | ||
/// when generating minified code | ||
/// </summary> | ||
/// <param name="asset"></param> | ||
/// <returns></returns> | ||
public static IAsset UseItemContent(this IAsset asset) | ||
{ | ||
asset.Processors.Add(new ItemContentEmitter()); | ||
return asset; | ||
} | ||
|
||
/// <summary> | ||
/// Changes the Asset to only emit to Response what is stored in | ||
/// asset.Items["Content"] | ||
/// and nothing else | ||
/// | ||
/// Useful for Generated Content | ||
/// | ||
/// Used by JavaScriptMinifier.AddJavaScriptBundle to emit sourcemaps into a separate Asset | ||
/// when generating minified code | ||
/// </summary> | ||
public static IEnumerable<IAsset> UseItemContent(this IEnumerable<IAsset> assets) | ||
{ | ||
return assets.AddProcessor(asset => asset.UseItemContent()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
|
||
namespace WebOptimizer.Processors | ||
{ | ||
public class JsSettings | ||
{ | ||
/// <summary> | ||
/// Defaults to false. | ||
/// Whether to generate source maps, allowing bundled code to be debugged using original source in places like Chrome Dev Tools. | ||
/// Respects .SymbolsMap on base class, CodeSettings; this setting is ignored (treated as false) if caller sets .SymbolsMap | ||
/// </summary> | ||
public bool GenerateSourceMap { get; set; } | ||
|
||
/// <summary> | ||
/// Set by the framework if GenerateSourceMap is true | ||
/// Helps a given Bundle Asset identify its SourceMap Asset to write to. | ||
/// </summary> | ||
public IAsset PipelineSourceMap { get; set; } | ||
|
||
/// <summary> | ||
/// NUglify is the underlying minifier for WebOptimizer. | ||
/// It's derived from Microsoft's AjaxMin. | ||
/// </summary> | ||
public NUglify.JavaScript.CodeSettings CodeSettings { get; set; } | ||
|
||
|
||
|
||
public JsSettings() | ||
{ | ||
CodeSettings = new NUglify.JavaScript.CodeSettings(); | ||
} | ||
public JsSettings(NUglify.JavaScript.CodeSettings nuglifyCodeSettings) | ||
{ | ||
CodeSettings = nuglifyCodeSettings; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.