Skip to content

Commit a9e1286

Browse files
committed
feat: respect baseUrl during development
BREAKING CHANGE: `devBaseUrl` option has been removed. `baseUrl` now works for both development and production. To use different paths for prod/dev, use conditional values based on `process.env.NODE_ENV` in `vue.config.js`.
1 parent 04600e6 commit a9e1286

File tree

7 files changed

+13
-24
lines changed

7 files changed

+13
-24
lines changed

docs/config.md

-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ module.exports = {
1313
// then change this to '/my-app/'
1414
baseUrl: '/',
1515

16-
// baseUrl, but for the dev server.
17-
// you'll only need this if you need to serve your dev server under
18-
// a specific sub-path in order to work with your dev setup.
19-
devBaseUrl: '/',
20-
2116
// where to output built files
2217
outputDir: 'dist',
2318

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,7 @@ module.exports = (api, options) => {
6464
if (!isProduction) {
6565
const devClients = [
6666
// dev server client
67-
require.resolve(`webpack-dev-server/client`) +
68-
// fix webpack-dev-server socket url to /sockjs-node
69-
// in case it uses options.devBaseUrl
70-
'?/sockjs-node',
67+
require.resolve(`webpack-dev-server/client`) + '?/sockjs-node',
7168
// hmr client
7269
require.resolve(projectDevServerOptions.hotOnly
7370
? 'webpack/hot/only-dev-server'
@@ -94,7 +91,8 @@ module.exports = (api, options) => {
9491
const urls = prepareURLs(
9592
useHttps ? 'https' : 'http',
9693
host,
97-
port
94+
port,
95+
options.baseUrl
9896
)
9997

10098
const proxySettings = prepareProxy(
@@ -108,15 +106,15 @@ module.exports = (api, options) => {
108106
historyApiFallback: {
109107
disableDotRule: true,
110108
rewrites: [
111-
{ from: /./, to: path.posix.join(options.devBaseUrl, 'index.html') }
109+
{ from: /./, to: path.posix.join(options.baseUrl, 'index.html') }
112110
]
113111
},
114112
contentBase: api.resolve('public'),
115113
watchContentBase: !isProduction,
116114
hot: !isProduction,
117115
quiet: true,
118116
compress: isProduction,
119-
publicPath: options.devBaseUrl,
117+
publicPath: options.baseUrl,
120118
overlay: isProduction // TODO disable this
121119
? false
122120
: { warnings: false, errors: true }

packages/@vue/cli-service/lib/config/dev.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = (api, options) => {
77
webpackConfig
88
.devtool('cheap-module-eval-source-map')
99
.output
10-
.publicPath(options.devBaseUrl)
10+
.publicPath(options.baseUrl)
1111

1212
webpackConfig
1313
.plugin('hmr')

packages/@vue/cli-service/lib/options.js

-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const { createSchema, validate } = require('@vue/cli-shared-utils')
22

33
const schema = createSchema(joi => joi.object({
44
baseUrl: joi.string(),
5-
devBaseUrl: joi.string(),
65
outputDir: joi.string(),
76
assetsDir: joi.string(),
87
runtimeCompiler: joi.boolean(),
@@ -48,9 +47,6 @@ exports.defaults = () => ({
4847
// project deployment base
4948
baseUrl: '/',
5049

51-
// baseUrl, but for the dev server.
52-
devBaseUrl: '/',
53-
5450
// where to output built files
5551
outputDir: 'dist',
5652

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ const url = require('url')
1010
const chalk = require('chalk')
1111
const address = require('address')
1212

13-
module.exports = function prepareUrls (protocol, host, port) {
13+
module.exports = function prepareUrls (protocol, host, port, pathname = '/') {
1414
const formatUrl = hostname =>
1515
url.format({
1616
protocol,
1717
hostname,
1818
port,
19-
pathname: '/'
19+
pathname
2020
})
2121
const prettyPrintUrl = hostname =>
2222
url.format({
2323
protocol,
2424
hostname,
2525
port: chalk.bold(port),
26-
pathname: '/'
26+
pathname
2727
})
2828

2929
const isUnspecifiedHost = host === '0.0.0.0' || host === '::'

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
const prefixRE = /^VUE_APP_/
22

33
module.exports = function resolveClientEnv (options, raw) {
4-
const isProd = process.env.NODE_ENV === 'production'
54
const env = {}
65
Object.keys(process.env).forEach(key => {
76
if (prefixRE.test(key) || key === 'NODE_ENV') {
87
env[key] = process.env[key]
98
}
109
})
11-
env.BASE_URL = isProd ? options.baseUrl : options.devBaseUrl
10+
env.BASE_URL = options.baseUrl
1211

1312
if (raw) {
1413
return env

packages/@vue/cli-ui/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
exports.clientAddonConfig = function ({ id, port = 8042 }) {
22
return {
3-
baseUrl: `/_addon/${id}`,
4-
devBaseUrl: `http://localhost:${port}/`,
3+
baseUrl: process.env.NODE_ENV === 'production'
4+
? `/_addon/${id}`
5+
: `http://localhost:${port}/`,
56
configureWebpack: {
67
output: {
78
// Important

0 commit comments

Comments
 (0)