Skip to content

Commit c5cfefb

Browse files
authored
Better handling of publicPath: 'auto' (#7005)
1 parent 75826d6 commit c5cfefb

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
hasProjectPnpm,
66
IpcMessenger
77
} = require('@vue/cli-shared-utils')
8+
const getBaseUrl = require('../util/getBaseUrl')
89

910
const defaults = {
1011
host: '0.0.0.0',
@@ -14,6 +15,7 @@ const defaults = {
1415

1516
/** @type {import('@vue/cli-service').ServicePlugin} */
1617
module.exports = (api, options) => {
18+
const baseUrl = getBaseUrl(options)
1719
api.registerCommand('serve', {
1820
description: 'start development server',
1921
usage: 'vue-cli-service serve [options] [entry]',
@@ -116,7 +118,7 @@ module.exports = (api, options) => {
116118
protocol,
117119
host,
118120
port,
119-
isAbsoluteUrl(options.publicPath) ? '/' : options.publicPath
121+
isAbsoluteUrl(baseUrl) ? '/' : baseUrl
120122
)
121123
const localUrlForBrowser = publicUrl || urls.localUrlForBrowser
122124

@@ -187,7 +189,7 @@ module.exports = (api, options) => {
187189
'text/html',
188190
'application/xhtml+xml'
189191
],
190-
rewrites: genHistoryApiFallbackRewrites(options.publicPath, options.pages)
192+
rewrites: genHistoryApiFallbackRewrites(baseUrl, options.pages)
191193
},
192194
hot: !isProduction
193195
}, projectDevServerOptions, {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function getBaseUrl (options) {
2+
return options.publicPath === 'auto' ? '' : options.publicPath
3+
}

packages/@vue/cli-service/lib/util/resolveClientEnv.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const getBaseUrl = require('./getBaseUrl')
12
const prefixRE = /^VUE_APP_/
23

34
module.exports = function resolveClientEnv (options, raw) {
@@ -7,7 +8,7 @@ module.exports = function resolveClientEnv (options, raw) {
78
env[key] = process.env[key]
89
}
910
})
10-
env.BASE_URL = options.publicPath
11+
env.BASE_URL = getBaseUrl(options)
1112

1213
if (raw) {
1314
return env

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy