Fix UseWebpackDevMiddleware with no options

This commit is contained in:
SteveSandersonMS
2016-03-24 11:39:38 +00:00
parent 980054b321
commit f1fa20afeb

View File

@@ -18,11 +18,12 @@ namespace Microsoft.AspNet.Builder
public static void UseWebpackDevMiddleware(this IApplicationBuilder appBuilder, WebpackDevMiddlewareOptions options = null) { public static void UseWebpackDevMiddleware(this IApplicationBuilder appBuilder, WebpackDevMiddlewareOptions options = null) {
// Validate options // Validate options
if (options != null) { if (options == null) {
options = new WebpackDevMiddlewareOptions();
}
if (options.ReactHotModuleReplacement && !options.HotModuleReplacement) { if (options.ReactHotModuleReplacement && !options.HotModuleReplacement) {
throw new ArgumentException("To enable ReactHotModuleReplacement, you must also enable HotModuleReplacement."); throw new ArgumentException("To enable ReactHotModuleReplacement, you must also enable HotModuleReplacement.");
} }
}
// Unlike other consumers of NodeServices, WebpackDevMiddleware dosen't share Node instances, nor does it // Unlike other consumers of NodeServices, WebpackDevMiddleware dosen't share Node instances, nor does it
// use your DI configuration. It's important for WebpackDevMiddleware to have its own private Node instance // use your DI configuration. It's important for WebpackDevMiddleware to have its own private Node instance
@@ -43,7 +44,7 @@ namespace Microsoft.AspNet.Builder
// Tell Node to start the server hosting webpack-dev-middleware // Tell Node to start the server hosting webpack-dev-middleware
var devServerOptions = new { var devServerOptions = new {
webpackConfigPath = Path.Combine(appEnv.ApplicationBasePath, options.ConfigFile ?? DefaultConfigFile), webpackConfigPath = Path.Combine(appEnv.ApplicationBasePath, options.ConfigFile ?? DefaultConfigFile),
suppliedOptions = options ?? new WebpackDevMiddlewareOptions() suppliedOptions = options
}; };
var devServerInfo = nodeServices.InvokeExport<WebpackDevServerInfo>(nodeScript.FileName, "createWebpackDevServer", JsonConvert.SerializeObject(devServerOptions)).Result; var devServerInfo = nodeServices.InvokeExport<WebpackDevServerInfo>(nodeScript.FileName, "createWebpackDevServer", JsonConvert.SerializeObject(devServerOptions)).Result;