[Vuejs]-Setup for env.development and env.production for vue3 project

0👍

The .env files (including .env.development) must be manually added to your project directory. However, you don’t need them to set BASE_URL, as BASE_URL is automatically set from the base config in vite.config.js:

import { defineConfig } from 'vite'

export default defineConfig({
  base: process.env.NODE_ENV === 'development'
         ? '/my/dev/baseurl/'
         : '/my/prod/baseurl/',
})

To reference environment variables in source, use import.meta.env instead of process.env:

// createWebHistory(process.env.BASE_URL), ❌
createWebHistory(import.meta.env.BASE_URL), ✅ 

demo

Leave a comment