Skip to content

Commit

Permalink
Better handling of publicPath: 'auto' (#7005)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiSoroka authored Mar 22, 2022
1 parent 75826d6 commit c5cfefb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/@vue/cli-service/lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
hasProjectPnpm,
IpcMessenger
} = require('@vue/cli-shared-utils')
const getBaseUrl = require('../util/getBaseUrl')

const defaults = {
host: '0.0.0.0',
Expand All @@ -14,6 +15,7 @@ const defaults = {

/** @type {import('@vue/cli-service').ServicePlugin} */
module.exports = (api, options) => {
const baseUrl = getBaseUrl(options)
api.registerCommand('serve', {
description: 'start development server',
usage: 'vue-cli-service serve [options] [entry]',
Expand Down Expand Up @@ -116,7 +118,7 @@ module.exports = (api, options) => {
protocol,
host,
port,
isAbsoluteUrl(options.publicPath) ? '/' : options.publicPath
isAbsoluteUrl(baseUrl) ? '/' : baseUrl
)
const localUrlForBrowser = publicUrl || urls.localUrlForBrowser

Expand Down Expand Up @@ -187,7 +189,7 @@ module.exports = (api, options) => {
'text/html',
'application/xhtml+xml'
],
rewrites: genHistoryApiFallbackRewrites(options.publicPath, options.pages)
rewrites: genHistoryApiFallbackRewrites(baseUrl, options.pages)
},
hot: !isProduction
}, projectDevServerOptions, {
Expand Down
3 changes: 3 additions & 0 deletions packages/@vue/cli-service/lib/util/getBaseUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function getBaseUrl (options) {
return options.publicPath === 'auto' ? '' : options.publicPath
}
3 changes: 2 additions & 1 deletion packages/@vue/cli-service/lib/util/resolveClientEnv.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const getBaseUrl = require('./getBaseUrl')
const prefixRE = /^VUE_APP_/

module.exports = function resolveClientEnv (options, raw) {
Expand All @@ -7,7 +8,7 @@ module.exports = function resolveClientEnv (options, raw) {
env[key] = process.env[key]
}
})
env.BASE_URL = options.publicPath
env.BASE_URL = getBaseUrl(options)

if (raw) {
return env
Expand Down

0 comments on commit c5cfefb

Please sign in to comment.