Skip to content

Commit

Permalink
v3.0.0:
Browse files Browse the repository at this point in the history
* Custom extensions for source map bundles.
* Breaking change: make codeMinify=true the default.
  • Loading branch information
benmccallum committed Jun 15, 2018
1 parent c9a50f6 commit d64b40e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
15 changes: 14 additions & 1 deletion AspNetBundling.TestWebsite/App_Start/BundleConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ public class BundleConfig
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptWithSourceMapBundle("~/bundles/jquery", null, true, true, ".bundle")
// Default (
bundles.Add(new ScriptWithSourceMapBundle("~/bundles/jquery")
.Include("~/Scripts/jquery-{version}.js"));

// Without providing a sourceMapExtension, appends "map" to end of bundleVirtualPath and works out-of-the-box
bundles.Add(new ScriptWithSourceMapBundle("~/bundles/jquery", null, true, true)
.Include("~/Scripts/jquery-{version}.js"));

// Providing a sourceMapExtension requires additional config of a handler for the extension (see web.config > handlers > *.map)
bundles.Add(new ScriptWithSourceMapBundle("~/bundles/jquery-with-dotmap-ext", null, true, true, ".map")
.Include("~/Scripts/jquery-{version}.js"));

// Providing a sourceMapExtension requires additional config of a handler for the extension (see web.config > handlers > *.bundle)
bundles.Add(new ScriptWithSourceMapBundle("~/bundles/jquery-with-dotbundle-ext", null, true, true, ".bundle")
.Include("~/Scripts/jquery-{version}.js"));

bundles.Add(new ScriptWithSourceMapBundle("~/bundles/jquery-no-important-comments", null, true, false)
Expand Down
1 change: 1 addition & 0 deletions AspNetBundling.TestWebsite/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
</div>

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jquery-with-custom-map-ext")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
Expand Down
1 change: 1 addition & 0 deletions AspNetBundling.TestWebsite/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<remove name="FormsAuthenticationModule"/>
</modules>
<handlers>
<add name="scriptBundle" verb="*" path="*.map" type="System.Web.Optimization.BundleHandler, System.Web.Optimization" preCondition="managedHandler" />
<add name="scriptBundle" verb="*" path="*.bundle" type="System.Web.Optimization.BundleHandler, System.Web.Optimization" preCondition="managedHandler" />
</handlers>
<staticContent>
Expand Down
4 changes: 2 additions & 2 deletions AspNetBundling/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.0.0.0")]
8 changes: 6 additions & 2 deletions AspNetBundling/ScriptWithSourceMapBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ public class ScriptWithSourceMapBundle : Bundle
{
/// <summary>
/// Initializes a new instance of the ScriptWithSourceMapBundle class that takes a virtual path for the bundle.
/// Config: no cdnPath, minifyCode on, preserveImportantComments on, source map path = bundleVirtualPath + "map"
/// </summary>
public ScriptWithSourceMapBundle(string virtualPath)
: this(virtualPath, null, false, true, DefaultSourceMapExtension)
: this(virtualPath, null, true, true, DefaultSourceMapExtension)
{

}

/// <summary>
/// Initializes a new instance of the ScriptWithSourceMapBundle class that takes a virtual path and a cdnPath for the bundle.
/// Config: cdnPath, minifyCode on, preserveImportantComments on, source map path = bundleVirtualPath + "map"
/// </summary>
public ScriptWithSourceMapBundle(string virtualPath, string cdnPath)
: this(virtualPath, cdnPath, true, true, DefaultSourceMapExtension)
Expand All @@ -29,6 +31,7 @@ public ScriptWithSourceMapBundle(string virtualPath, string cdnPath)
/// <summary>
/// Initializes a new instance of the ScriptWithSourceMapBundle class that takes a virtual path
/// and allows code minification to be toggled.
/// Config: no cdnPath, minifyCode as passed, preserveImportantComments on, source map path = bundleVirtualPath + "map"
/// </summary>
/// <param name="minifyCode">Preserve variables names in scripts </param>
public ScriptWithSourceMapBundle(string virtualPath, bool minifyCode)
Expand All @@ -40,10 +43,11 @@ public ScriptWithSourceMapBundle(string virtualPath, bool minifyCode)
/// <summary>
/// Initializes a new instance of the ScriptWithSourceMapBundle that takes a virtual path, a cdnPath,
/// allows code minification to be toggled and preservation of important comments.
/// Config: all as passed, source map path = bundleVirtualPath + "map"
/// </summary>
/// <param name="preserveImportantComments">Toggle to preserve important comments when needed (e.g. legal requirement for a library)</param>
public ScriptWithSourceMapBundle(string virtualPath, string cdnPath, bool minifyCode, bool preserveImportantComments)
: this(virtualPath, null, minifyCode, preserveImportantComments, DefaultSourceMapExtension)
: this(virtualPath, cdnPath, minifyCode, preserveImportantComments, DefaultSourceMapExtension)
{

}
Expand Down
2 changes: 1 addition & 1 deletion AspNetBundling/ScriptWithSourceMapBundleBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static void AddContentToAdHocBundle(BundleContext context, string virtua

const string sourceMappingDisabledMsg = "/* Source mapping won't work properly right now, sorry! The debugger is attached and the following bug exists in AjaxMin: https://ajaxmin.codeplex.com/workitem/21834 */";

internal bool minifyCode = false;
internal bool minifyCode = true;

internal bool preserveImportantComments = true;

Expand Down
Binary file modified AspNetBundling/nuget.exe
Binary file not shown.

0 comments on commit d64b40e

Please sign in to comment.