process.env.BASE_URL
is automatically injected into Webpack configuration by Vue CLI with the value specified in CLI config (vue.config.js
) variable publicPath
What is it used for ?
From the docs:
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 publicPath
instead of modifying webpack output.publicPath
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/'
So in Webpack it is used to link to additional resources (images, fonts, code chunks when code-splitting)
The same purpose is in Vue Router because it also creates links (to other parts of your application) via <router-link>
For example with this route:
{
path: "/page1",
name: "Page 1",
component: Page1
}
and this in your template:
<router-link to="/page1">Page 1</router-link>
If router is set to base: '/'
(default), the link will be rendered as
<a href="/page1" class="">Page 1</a>
but with base: '/my-app/'
, the link becomes
<a href="/my-app/page1" class="">Page 1</a>
You can read more about Absolute vs relative URLs here