Skip to content

Commit

Permalink
#11 Add option for specifying the development tool that is used from …
Browse files Browse the repository at this point in the history
…webpack
  • Loading branch information
xabikos committed Feb 21, 2016
1 parent bcff3d6 commit 1e74bca
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Webpack/ArgumentsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Linq;
using System.Text;
using Webpack.Extensions;

namespace Webpack {
internal class ArgumentsHelper {

private const string DefaultDevFile = "--config webpack/webpack.dev.js ";
private const string DevToolType = "--devtool {0} ";
private const string CssFiles = "--module-bind css=style!css ";
private const string LessFiles = "--module-bind less=style!css!less ";
private const string SassFiles = "--module-bind scss=style!css!sass ";
Expand Down Expand Up @@ -41,6 +43,7 @@ public static string GetWebpackArguments(string rootPath, WebpackOptions options
result.Append($"--entry ./{options.EntryPoint} ");
result.Append($"--output-path {rootPath} ");
result.Append($"--output-filename {options.OutputFileName} ");
result.Append(string.Format(DevToolType, options.DevToolType.GetWebpackValue()));

if(options.EnableHotLoading) {
result.Append("--hot --inline ");
Expand Down
29 changes: 29 additions & 0 deletions src/Webpack/Extensions/DevToolTypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Webpack.Extensions {

/// <summary>
/// Contains extensions methods for <see cref="DevToolType"/>
/// </summary>
public static class DevToolTypeExtensions {

/// <summary>
/// Returns the webpack required value for the provided <paramref name="devToolType"/>
/// </summary>
public static string GetWebpackValue(this DevToolType devToolType) {
switch (devToolType) {
case DevToolType.Eval:
return "eval";
case DevToolType.CheapEvalSourceMap:
return "cheap-eval-source-map";
case DevToolType.CheapSourceMap:
return "cheap-source-map";
case DevToolType.CheapModuleEvalSourceMap:
return "cheap-module-eval-source-map";
case DevToolType.EvalSourceMap:
return "eval-source-map";
case DevToolType.SourceMap:
return "source-map";
}
return "source-map";
}
}
}
17 changes: 17 additions & 0 deletions src/Webpack/WebpackOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public WebpackOptions(
bool handleStyles = true) {
EntryPoint = entryPoint;
OutputFileName = outputFileName;
DevToolType = DevToolType.SourceMap;
EnableES2015 = true;
HandleStyles = handleStyles;
DevServerOptions = new WebpackDevServerOptions();
Expand All @@ -33,6 +34,12 @@ public WebpackOptions(
/// </summary>
public string OutputFileName { get; set; }

/// <summary>
/// Indicates the type of the development tool will be used by webpack. See http://webpack.github.io/docs/configuration.html#devtool
/// Default to source-map
/// </summary>
public DevToolType DevToolType { get; set; }

/// <summary>
/// Flag that enables ES2015 features (requires babel-loader to be installed)
/// It's enabled <c>true</c> by default
Expand Down Expand Up @@ -95,6 +102,16 @@ public enum StylesType {
Sass
}

public enum DevToolType {
Eval,
CheapEvalSourceMap,
CheapSourceMap,
CheapModuleEvalSourceMap,
CheapModuleSourceMap,
EvalSourceMap,
SourceMap
}

public enum StaticFileType {
Png,
Jpg,
Expand Down
2 changes: 1 addition & 1 deletion src/Webpack/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.2.2",
"version": "1.2.3",
"title": "Webpack",
"description": "Webpack extension methods and middleware for using module bundling in an ASP.NET 5 application",
"authors": [ "Charalampos Karypidis" ],
Expand Down

0 comments on commit 1e74bca

Please sign in to comment.