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
})
This is a quick tutorial on how to create and access environment variables in Vue 3 with a dotenv ( . env ) file. Vue 3 apps built with Vite support dotenv environment variables out of the box, so all you need to do is add a . env file to the root folder of your Vue project.
In Node. js, process. env is a global variable that is injected during runtime. It is a view of the state of the system environment variables. When we set an environment variable, it is loaded into process.
You can access it from process. env. NODE_ENV . This variable changes based on what mode you are currently in.
The CLI ( @vue/cli ) is a globally installed npm package and provides the vue command in your terminal. It provides the ability to quickly scaffold a new project via vue create . You can also manage your projects using a graphical user interface via vue ui .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With