Skip to content

Commit da38ed4

Browse files
committed
fix: fix hmr in docker + support devServer.public with protocol
1 parent 7d65353 commit da38ed4

File tree

1 file changed

+11
-11
lines changed
  • packages/@vue/cli-service/lib/commands

1 file changed

+11
-11
lines changed

packages/@vue/cli-service/lib/commands/serve.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ module.exports = (api, options) => {
3232
const isProduction = process.env.NODE_ENV === 'production'
3333

3434
const path = require('path')
35-
const url = require('url')
3635
const chalk = require('chalk')
3736
const webpack = require('webpack')
3837
const WebpackDevServer = require('webpack-dev-server')
@@ -69,7 +68,12 @@ module.exports = (api, options) => {
6968
const host = args.host || process.env.HOST || projectDevServerOptions.host || defaults.host
7069
portfinder.basePort = args.port || process.env.PORT || projectDevServerOptions.port || defaults.port
7170
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-zA-Z]+:\/\//.test(rawPublicUrl)
74+
? rawPublicUrl
75+
: `${protocol}://${rawPublicUrl}`
76+
: null
7377

7478
const urls = prepareURLs(
7579
protocol,
@@ -85,16 +89,12 @@ module.exports = (api, options) => {
8589

8690
// inject dev & hot-reload middleware entries
8791
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+
: ``
9595
const devClients = [
9696
// dev server client
97-
require.resolve(`webpack-dev-server/client`) + `?${sockjsUrl}`,
97+
require.resolve(`webpack-dev-server/client`) + sockjsUrl,
9898
// hmr client
9999
require.resolve(projectDevServerOptions.hotOnly
100100
? 'webpack/hot/only-dev-server'
@@ -183,7 +183,7 @@ module.exports = (api, options) => {
183183
}
184184

185185
const networkUrl = publicUrl
186-
? (protocol + '://' + publicUrl).replace(/([^/])$/, '$1/')
186+
? publicUrl.replace(/([^/])$/, '$1/')
187187
: urls.lanUrlForTerminal
188188
console.log()
189189
console.log([

0 commit comments

Comments
 (0)