1

I created a project with Vue CLI 4.1.2, and inside router/index.js, I found:

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

There is no .env file in the project root. So what does process.env.BASE_URL mean? Where is the BASE_URL value set?

tony19
  • 125,647
  • 18
  • 229
  • 307
Istiaque Ahmed
  • 6,072
  • 24
  • 75
  • 141

1 Answers1

0

process.env is a property that contains the user's environment variables in Node. The .env is an optional file that could be used in Vue CLI projects to create additional environment variables. Note that you could also create .env.production and .env.development files to set variables specific to the current build mode.

BASE_URL is an environment variable automatically set by Vue CLI when running serve or build NPM scripts. Its default value is /, but it can be configured in <projectRoot>/vue.config.js with the baseUrl (deprecated) or publicPath setting:

// vue.config.js
module.exports = {
  publicPath: '/my-app/'
}
tony19
  • 125,647
  • 18
  • 229
  • 307