Skip to content

Commit de960d8

Browse files
Allow explicit configuration of port number for webpack dev middleware server. Fixes aspnet#223.
1 parent 14337e3 commit de960d8

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/Microsoft.AspNetCore.SpaServices/Webpack/WebpackDevMiddlewareOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace Microsoft.AspNetCore.SpaServices.Webpack
33
public class WebpackDevMiddlewareOptions
44
{
55
public bool HotModuleReplacement { get; set; }
6+
public int HotModuleReplacementServerPort { get; set; }
67
public bool ReactHotModuleReplacement { get; set; }
78
public string ConfigFile { get; set; }
89
}

src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aspnet-webpack",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.",
55
"main": "index.js",
66
"scripts": {

src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface CreateDevServerOptions {
1616
// These are the options configured in C# and then JSON-serialized, hence the C#-style naming
1717
interface DevServerOptions {
1818
HotModuleReplacement: boolean;
19+
HotModuleReplacementServerPort: number;
1920
ReactHotModuleReplacement: boolean;
2021
}
2122

@@ -35,9 +36,11 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
3536
return;
3637
}
3738

39+
// The default value, 0, means 'choose randomly'
40+
const suggestedHMRPortOrZero = options.suppliedOptions.HotModuleReplacementServerPort;
41+
3842
const app = connect();
39-
const defaultPort = 0; // 0 means 'choose randomly'. Could allow an explicit value to be supplied instead.
40-
const listener = app.listen(defaultPort, () => {
43+
const listener = app.listen(suggestedHMRPortOrZero, () => {
4144
// Build the final Webpack config based on supplied options
4245
if (enableHotModuleReplacement) {
4346
// TODO: Stop assuming there's an entry point called 'main'

0 commit comments

Comments
 (0)