Allow explicit configuration of port number for webpack dev middleware server. Fixes #223.

This commit is contained in:
SteveSandersonMS
2016-07-27 11:13:09 +01:00
parent 14337e32ab
commit de960d80aa
3 changed files with 7 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack
public class WebpackDevMiddlewareOptions
{
public bool HotModuleReplacement { get; set; }
public int HotModuleReplacementServerPort { get; set; }
public bool ReactHotModuleReplacement { get; set; }
public string ConfigFile { get; set; }
}

View File

@@ -1,6 +1,6 @@
{
"name": "aspnet-webpack",
"version": "1.0.7",
"version": "1.0.8",
"description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.",
"main": "index.js",
"scripts": {

View File

@@ -16,6 +16,7 @@ interface CreateDevServerOptions {
// These are the options configured in C# and then JSON-serialized, hence the C#-style naming
interface DevServerOptions {
HotModuleReplacement: boolean;
HotModuleReplacementServerPort: number;
ReactHotModuleReplacement: boolean;
}
@@ -35,9 +36,11 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
return;
}
// The default value, 0, means 'choose randomly'
const suggestedHMRPortOrZero = options.suppliedOptions.HotModuleReplacementServerPort;
const app = connect();
const defaultPort = 0; // 0 means 'choose randomly'. Could allow an explicit value to be supplied instead.
const listener = app.listen(defaultPort, () => {
const listener = app.listen(suggestedHMRPortOrZero, () => {
// Build the final Webpack config based on supplied options
if (enableHotModuleReplacement) {
// TODO: Stop assuming there's an entry point called 'main'