16

When I manually selected presets when installing vue using vue cli. I stumbled upon process.env.BASE_URL. I was tryng to find it in the internet but to no avail, I can't find any decent explanation. Here's the code.

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
1
  • 1
    you must have .env file in your root folder where you define value for BASE_URL Commented Nov 5, 2019 at 3:02

1 Answer 1

10

the documentation is here https://cli.vuejs.org/guide/mode-and-env.html#environment-variables

It has a system of cascading files that will determine enviroment variables for your app. The main file being a .env

The BASE_URL is semi arbitary, you could introduce your own BASE_ROUTER_URL variable if you wanted

Sign up to request clarification or add additional context in comments.

5 Comments

I do not see any .env file in my project root. Where is it actually ?
via vue ui? I don't think it makes them by default, so just make it yourself. Read the info in the link. It has a pretty good description of how they work
no, i created the project via vue create project_name. No .env file in the project root. Then how could it use process.env in the router as said in OP ?
BASE_URL is not arbitrary. (doc) BASE_URL - this corresponds to the publicPath option in vue.config.js and is the base path your app is deployed at.
you need to create the .env file yourself. You should have different .env file for production .env and development: .env.development. You need to use the vue-cli-service serve --mode development to run your project in development mode.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.