Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of publicPath: 'auto' #7005

Merged
merged 7 commits into from Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/@vue/cli-service/lib/commands/serve.js
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
@@ -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
@@ -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