Skip to content

Commit

Permalink
support publicPath auto
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiSoroka committed Mar 18, 2022
1 parent de71144 commit e2cf91a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 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,9 +118,7 @@ module.exports = (api, options) => {
protocol,
host,
port,
isAbsoluteUrl(options.publicPath) || options.publicPath === 'auto'
? '/'
: options.publicPath
isAbsoluteUrl(baseUrl) ? '/' : baseUrl
)
const localUrlForBrowser = publicUrl || urls.localUrlForBrowser

Expand Down Expand Up @@ -189,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

0 comments on commit e2cf91a

Please sign in to comment.