@@ -32,7 +32,6 @@ module.exports = (api, options) => {
32
32
const isProduction = process . env . NODE_ENV === 'production'
33
33
34
34
const path = require ( 'path' )
35
- const url = require ( 'url' )
36
35
const chalk = require ( 'chalk' )
37
36
const webpack = require ( 'webpack' )
38
37
const WebpackDevServer = require ( 'webpack-dev-server' )
@@ -69,7 +68,12 @@ module.exports = (api, options) => {
69
68
const host = args . host || process . env . HOST || projectDevServerOptions . host || defaults . host
70
69
portfinder . basePort = args . port || process . env . PORT || projectDevServerOptions . port || defaults . port
71
70
const port = await portfinder . getPortPromise ( )
72
- const publicUrl = args . public || projectDevServerOptions . public
71
+ const rawPublicUrl = args . public || projectDevServerOptions . public
72
+ const publicUrl = rawPublicUrl
73
+ ? / ^ [ a - z A - Z ] + : \/ \/ / . test ( rawPublicUrl )
74
+ ? rawPublicUrl
75
+ : `${ protocol } ://${ rawPublicUrl } `
76
+ : null
73
77
74
78
const urls = prepareURLs (
75
79
protocol ,
@@ -85,16 +89,12 @@ module.exports = (api, options) => {
85
89
86
90
// inject dev & hot-reload middleware entries
87
91
if ( ! isProduction ) {
88
- const sockjsUrl = publicUrl ? `//${ publicUrl } /sockjs-node` : url . format ( {
89
- protocol,
90
- port,
91
- hostname : urls . lanUrlForConfig || 'localhost' ,
92
- pathname : '/sockjs-node'
93
- } )
94
-
92
+ const sockjsUrl = publicUrl
93
+ ? `?${ publicUrl } /sockjs-node`
94
+ : ``
95
95
const devClients = [
96
96
// dev server client
97
- require . resolve ( `webpack-dev-server/client` ) + `? ${ sockjsUrl } ` ,
97
+ require . resolve ( `webpack-dev-server/client` ) + sockjsUrl ,
98
98
// hmr client
99
99
require . resolve ( projectDevServerOptions . hotOnly
100
100
? 'webpack/hot/only-dev-server'
@@ -183,7 +183,7 @@ module.exports = (api, options) => {
183
183
}
184
184
185
185
const networkUrl = publicUrl
186
- ? ( protocol + '://' + publicUrl ) . replace ( / ( [ ^ / ] ) $ / , '$1/' )
186
+ ? publicUrl . replace ( / ( [ ^ / ] ) $ / , '$1/' )
187
187
: urls . lanUrlForTerminal
188
188
console . log ( )
189
189
console . log ( [
0 commit comments