@@ -30,6 +30,7 @@ module.exports = (api, options) => {
30
30
const isProduction = process . env . NODE_ENV === 'production'
31
31
32
32
const path = require ( 'path' )
33
+ const url = require ( 'url' )
33
34
const chalk = require ( 'chalk' )
34
35
const webpack = require ( 'webpack' )
35
36
const WebpackDevServer = require ( 'webpack-dev-server' )
@@ -60,11 +61,37 @@ module.exports = (api, options) => {
60
61
}
61
62
}
62
63
64
+ // resolve server options
65
+ const useHttps = args . https || projectDevServerOptions . https || defaults . https
66
+ const protocol = useHttps ? 'https' : 'http'
67
+ const host = args . host || process . env . HOST || projectDevServerOptions . host || defaults . host
68
+ portfinder . basePort = args . port || process . env . PORT || projectDevServerOptions . port || defaults . port
69
+ const port = await portfinder . getPortPromise ( )
70
+
71
+ const urls = prepareURLs (
72
+ protocol ,
73
+ host ,
74
+ port ,
75
+ options . baseUrl
76
+ )
77
+
78
+ const proxySettings = prepareProxy (
79
+ projectDevServerOptions . proxy ,
80
+ api . resolve ( 'public' )
81
+ )
82
+
63
83
// inject dev & hot-reload middleware entries
64
84
if ( ! isProduction ) {
85
+ const sockjsUrl = url . format ( {
86
+ protocol,
87
+ port,
88
+ hostname : urls . lanUrlForConfig || 'localhost' ,
89
+ pathname : '/sockjs-node'
90
+ } )
91
+
65
92
const devClients = [
66
93
// dev server client
67
- require . resolve ( `webpack-dev-server/client` ) + ( options . baseUrl !== '/' ? '?/sockjs-node' : '' ) ,
94
+ require . resolve ( `webpack-dev-server/client` ) + `? ${ sockjsUrl } ` ,
68
95
// hmr client
69
96
require . resolve ( projectDevServerOptions . hotOnly
70
97
? 'webpack/hot/only-dev-server'
@@ -82,24 +109,6 @@ module.exports = (api, options) => {
82
109
// create compiler
83
110
const compiler = webpack ( webpackConfig )
84
111
85
- // resolve server options
86
- const useHttps = args . https || projectDevServerOptions . https || defaults . https
87
- const host = args . host || process . env . HOST || projectDevServerOptions . host || defaults . host
88
- portfinder . basePort = args . port || process . env . PORT || projectDevServerOptions . port || defaults . port
89
- const port = await portfinder . getPortPromise ( )
90
-
91
- const urls = prepareURLs (
92
- useHttps ? 'https' : 'http' ,
93
- host ,
94
- port ,
95
- options . baseUrl
96
- )
97
-
98
- const proxySettings = prepareProxy (
99
- projectDevServerOptions . proxy ,
100
- api . resolve ( 'public' )
101
- )
102
-
103
112
// create server
104
113
const server = new WebpackDevServer ( compiler , Object . assign ( {
105
114
clientLogLevel : 'none' ,
0 commit comments