Skip to content

Commit e7af0d8

Browse files
authored
feat: deprecate confusing baseUrl option, use publicPath instead. (#3143)
* feat: deprecate confusing `baseUrl` option, use `publicPath` instead. * fix: do not touch CHANGELOG.md * docs: links referring baseUrl now changed to publicPath
1 parent 8b4471e commit e7af0d8

28 files changed

+158
-105
lines changed

docs/config/README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ module.exports = {
3131

3232
### baseUrl
3333

34+
Deprecated since Vue CLI 3.3, please use [`publicPath`](#publicPath) instead.
35+
36+
### publicPath
37+
3438
- Type: `string`
3539
- Default: `'/'`
3640

37-
The base URL your application bundle will be deployed at. This is the equivalent of webpack's `output.publicPath`, but Vue CLI also needs this value for other purposes, so you should **always use `baseUrl` instead of modifying webpack `output.publicPath`**.
41+
The base URL your application bundle will be deployed at (known as `baseUrl` before Vue CLI 3.3). This is the equivalent of webpack's `output.publicPath`, but Vue CLI also needs this value for other purposes, so you should **always use `publicPath` instead of modifying webpack `output.publicPath`**.
3842

39-
By default, Vue CLI assumes your app will be deployed at the root of a domain, e.g. `https://www.my-app.com/`. If your app is deployed at a sub-path, you will need to specify that sub-path using this option. For example, if your app is deployed at `https://www.foobar.com/my-app/`, set `baseUrl` to `'/my-app/'`.
43+
By default, Vue CLI assumes your app will be deployed at the root of a domain, e.g. `https://www.my-app.com/`. If your app is deployed at a sub-path, you will need to specify that sub-path using this option. For example, if your app is deployed at `https://www.foobar.com/my-app/`, set `publicPath` to `'/my-app/'`.
4044

4145
The value can also be set to an empty string (`''`) or a relative path (`./`) so that all assets are linked using relative paths. This allows the built bundle to be deployed under any public path, or used in a file system based environment like a Cordova hybrid app.
4246

43-
::: warning Limitations of relative baseUrl
44-
Relative `baseUrl` has some limitations and should be avoided when:
47+
::: warning Limitations of relative publicPath
48+
Relative `publicPath` has some limitations and should be avoided when:
4549

4650
- You are using HTML5 `history.pushState` routing;
4751

@@ -52,7 +56,7 @@ module.exports = {
5256

5357
``` js
5458
module.exports = {
55-
baseUrl: process.env.NODE_ENV === 'production'
59+
publicPath: process.env.NODE_ENV === 'production'
5660
? '/production-sub-path/'
5761
: '/'
5862
}
@@ -304,7 +308,7 @@ module.exports = {
304308

305309
- Some values like `host`, `port` and `https` may be overwritten by command line flags.
306310

307-
- Some values like `publicPath` and `historyApiFallback` should not be modified as they need to be synchronized with [baseUrl](#baseurl) for the dev server to function properly.
311+
- Some values like `publicPath` and `historyApiFallback` should not be modified as they need to be synchronized with [publicPath](#baseurl) for the dev server to function properly.
308312

309313
### devServer.proxy
310314

docs/guide/deployment.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
If you are using Vue CLI along with a backend framework that handles static assets as part of its deployment, all you need to do is make sure Vue CLI generates the built files in the correct location, and then follow the deployment instruction of your backend framework.
66

7-
If you are developing your frontend app separately from your backend - i.e. your backend exposes an API for your frontend to talk to, then your frontend is essentially a purely static app. You can deploy the built content in the `dist` directory to any static file server, but make sure to set the correct [baseUrl](../config/#baseurl).
7+
If you are developing your frontend app separately from your backend - i.e. your backend exposes an API for your frontend to talk to, then your frontend is essentially a purely static app. You can deploy the built content in the `dist` directory to any static file server, but make sure to set the correct [publicPath](../config/#publicpath).
88

99
### Previewing Locally
1010

11-
The `dist` directory is meant to be served by an HTTP server (unless you've configured `baseUrl` to be a relative value), so it will not work if you open `dist/index.html` directly over `file://` protocol. The easiest way to preview your production build locally is using a Node.js static file server, for example [serve](https://github.com/zeit/serve):
11+
The `dist` directory is meant to be served by an HTTP server (unless you've configured `publicPath` to be a relative value), so it will not work if you open `dist/index.html` directly over `file://` protocol. The easiest way to preview your production build locally is using a Node.js static file server, for example [serve](https://github.com/zeit/serve):
1212

1313
``` bash
1414
npm install -g serve
@@ -35,15 +35,15 @@ If you are using the PWA plugin, your app must be served over HTTPS so that [Ser
3535

3636
### GitHub Pages
3737

38-
1. Set correct `baseUrl` in `vue.config.js`.
38+
1. Set correct `publicPath` in `vue.config.js`.
3939

40-
If you are deploying to `https://<USERNAME>.github.io/`, you can omit `baseUrl` as it defaults to `"/"`.
40+
If you are deploying to `https://<USERNAME>.github.io/`, you can omit `publicPath` as it defaults to `"/"`.
4141

42-
If you are deploying to `https://<USERNAME>.github.io/<REPO>/`, (i.e. your repository is at `https://github.com/<USERNAME>/<REPO>`), set `baseUrl` to `"/<REPO>/"`. For example, if your repo name is "my-project", your `vue.config.js` should look like this:
42+
If you are deploying to `https://<USERNAME>.github.io/<REPO>/`, (i.e. your repository is at `https://github.com/<USERNAME>/<REPO>`), set `publicPath` to `"/<REPO>/"`. For example, if your repo name is "my-project", your `vue.config.js` should look like this:
4343

4444
``` js
4545
module.exports = {
46-
baseUrl: process.env.NODE_ENV === 'production'
46+
publicPath: process.env.NODE_ENV === 'production'
4747
? '/my-project/'
4848
: '/'
4949
}
@@ -112,7 +112,7 @@ Typically, your static website will be hosted on https://yourUserName.gitlab.io/
112112
// make sure you update `yourProjectName` with the name of your GitLab project
113113
114114
module.exports = {
115-
baseUrl: process.env.NODE_ENV === 'production'
115+
publicPath: process.env.NODE_ENV === 'production'
116116
? '/yourProjectName/'
117117
: '/'
118118
}
@@ -291,11 +291,11 @@ Verify your project is successfully published by Surge by visiting `myawesomepro
291291
292292
1. As described in the [Bitbucket documentation](https://confluence.atlassian.com/bitbucket/publishing-a-website-on-bitbucket-cloud-221449776.html) you need to create a repository named exactly `<USERNAME>.bitbucket.io`.
293293
294-
2. It is possible to publish to a subfolder of the main repository, for instance if you want to have multiple websites. In that case set correct `baseUrl` in `vue.config.js`.
294+
2. It is possible to publish to a subfolder of the main repository, for instance if you want to have multiple websites. In that case set correct `publicPath` in `vue.config.js`.
295295
296-
If you are deploying to `https://<USERNAME>.bitbucket.io/`, you can omit `baseUrl` as it defaults to `"/"`.
296+
If you are deploying to `https://<USERNAME>.bitbucket.io/`, you can omit `publicPath` as it defaults to `"/"`.
297297
298-
If you are deploying to `https://<USERNAME>.bitbucket.io/<SUBFOLDER>/`, set `baseUrl` to `"/<SUBFOLDER>/"`. In this case the directory structure of the repository should reflect the url structure, for instance the repository should have a `/<SUBFOLDER>` directory.
298+
If you are deploying to `https://<USERNAME>.bitbucket.io/<SUBFOLDER>/`, set `publicPath` to `"/<SUBFOLDER>/"`. In this case the directory structure of the repository should reflect the url structure, for instance the repository should have a `/<SUBFOLDER>` directory.
299299
300300
3. Inside your project, create `deploy.sh` with the following content and run it to deploy:
301301

docs/guide/html-and-static-assets.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ In addition to the [default values exposed by `html-webpack-plugin`](https://git
2121
```
2222

2323
See also:
24-
- [baseUrl](../config/#baseurl)
24+
- [publicPath](../config/#publicpath)
2525

2626
### Preload
2727

@@ -166,7 +166,7 @@ Note we recommend importing assets as part of your module dependency graph so th
166166
- Missing files cause compilation errors instead of 404 errors for your users.
167167
- Result filenames include content hashes so you don’t need to worry about browsers caching their old versions.
168168

169-
The `public` directory is provided as an **escape hatch**, and when you reference it via absolute path, you need to take into account where your app will be deployed. If your app is not deployed at the root of a domain, you will need to prefix your URLs with the [baseUrl](../config/#baseurl):
169+
The `public` directory is provided as an **escape hatch**, and when you reference it via absolute path, you need to take into account where your app will be deployed. If your app is not deployed at the root of a domain, you will need to prefix your URLs with the [publicPath](../config/#publicpath):
170170

171171
- In `public/index.html` or other HTML files used as templates by `html-webpack-plugin`, you need to prefix the link with `<%= BASE_URL %>`:
172172

@@ -179,15 +179,15 @@ The `public` directory is provided as an **escape hatch**, and when you referenc
179179
``` js
180180
data () {
181181
return {
182-
baseUrl: process.env.BASE_URL
182+
publicPath: process.env.BASE_URL
183183
}
184184
}
185185
```
186186

187187
Then:
188188

189189
``` html
190-
<img :src="`${baseUrl}my-image.png`">
190+
<img :src="`${publicPath}my-image.png`">
191191
```
192192

193193
### When to use the `public` folder

docs/guide/mode-and-env.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ During build, `process.env.VUE_APP_SECRET` will be replaced by the corresponding
8181
In addition to `VUE_APP_*` variables, there are also two special variables that will always be available in your app code:
8282

8383
- `NODE_ENV` - this will be one of `"development"`, `"production"` or `"test"` depending on the [mode](#modes) the app is running in.
84-
- `BASE_URL` - this corresponds to the `baseUrl` option in `vue.config.js` and is the base path your app is deployed at.
84+
- `BASE_URL` - this corresponds to the `publicPath` option in `vue.config.js` and is the base path your app is deployed at.
8585

8686
All resolved env variables will be available inside `public/index.html` as discussed in [HTML - Interpolation](./html-and-static-assets.md#interpolation).
8787

docs/guide/webpack.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
The object will be merged into the final webpack config using [webpack-merge](https://github.com/survivejs/webpack-merge).
1919

2020
::: warning
21-
Some webpack options are set based on values in `vue.config.js` and should not be mutated directly. For example, instead of modifying `output.path`, you should use the `outputDir` option in `vue.config.js`; instead of modifying `output.publicPath`, you should use the `baseUrl` option in `vue.config.js`. This is because the values in `vue.config.js` will be used in multiple places inside the config to ensure everything works properly together.
21+
Some webpack options are set based on values in `vue.config.js` and should not be mutated directly. For example, instead of modifying `output.path`, you should use the `outputDir` option in `vue.config.js`; instead of modifying `output.publicPath`, you should use the `publicPath` option in `vue.config.js`. This is because the values in `vue.config.js` will be used in multiple places inside the config to ensure everything works properly together.
2222
:::
2323

2424
If you need conditional behavior based on the environment, or want to directly mutate the config, use a function (which will be lazy evaluated after the env variables are set). The function receives the resolved config as the argument. Inside the function, you can either mutate the config directly, OR return an object which will be merged:

docs/ru/config/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ module.exports = {
2929
}
3030
```
3131

32-
### baseUrl
32+
### publicPath
3333

3434
- Тип: `string`
3535
- По умолчанию: `'/'`
3636

37-
Базовый URL-адрес сборки вашего приложения, по которому оно будет опубликовано. Это аналог опции webpack `output.publicPath`, но Vue CLI также использует это значение в других целях, поэтому вы должны **всегда использовать `baseUrl` вместо изменения опции `output.publicPath`**.
37+
Базовый URL-адрес сборки вашего приложения, по которому оно будет опубликовано. Это аналог опции webpack `output.publicPath`, но Vue CLI также использует это значение в других целях, поэтому вы должны **всегда использовать `publicPath` вместо изменения опции `output.publicPath`**.
3838

39-
По умолчанию Vue CLI считает, что публикация будет выполнена в корень домена, например `https://www.my-app.com/`. Если приложение публикуется в подкаталог, то необходимо указать этот путь с помощью этой опции. Например, если приложение будет публиковаться по адресу `https://www.foobar.com/my-app/`, установите `baseUrl` в значение `'/my-app/'`.
39+
По умолчанию Vue CLI считает, что публикация будет выполнена в корень домена, например `https://www.my-app.com/`. Если приложение публикуется в подкаталог, то необходимо указать этот путь с помощью этой опции. Например, если приложение будет публиковаться по адресу `https://www.foobar.com/my-app/`, установите `publicPath` в значение `'/my-app/'`.
4040

4141
Значение также может быть пустой строкой (`''`) или относительным путём (`./`), чтобы все ресурсы подключались через относительные пути. Это позволит публиковать сборку в любой публичный каталог, или использовать в окружении файловой системы, например в гибридном приложении Cordova.
4242

43-
::: warning Ограничения относительного baseUrl
44-
Относительный `baseUrl` имеет некоторые ограничения и его следует избегать если:
43+
::: warning Ограничения относительного publicPath
44+
Относительный `publicPath` имеет некоторые ограничения и его следует избегать если:
4545

4646
- Вы используете маршрутизацию HTML5 `history.pushState`;
4747

@@ -52,7 +52,7 @@ module.exports = {
5252

5353
``` js
5454
module.exports = {
55-
baseUrl: process.env.NODE_ENV === 'production'
55+
publicPath: process.env.NODE_ENV === 'production'
5656
? '/production-sub-path/'
5757
: '/'
5858
}
@@ -304,7 +304,7 @@ module.exports = {
304304

305305
- Некоторые значения, такие как `host`, `port` и `https`, могут перезаписываться флагами командной строки.
306306

307-
- Некоторые значения, такие как `publicPath` и `historyApiFallback`, нельзя изменять, поскольку они должны быть синхронизированы с [baseUrl](#baseurl) для правильной работы сервера разработки.
307+
- Некоторые значения, такие как `publicPath` и `historyApiFallback`, нельзя изменять, поскольку они должны быть синхронизированы с [publicPath](#baseurl) для правильной работы сервера разработки.
308308

309309
### devServer.proxy
310310

0 commit comments

Comments
 (0)