You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import { fileURLToPath , URL } from 'node:url'
import { defineConfig , loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
// Element-Plus 按需导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vite.dev/config/
export default defineConfig ( ( { mode } ) = > {
// 根据当前工作目录( process.cwd())中的 `mode` 加载 .env 文件
// 设置第三个参数为 '' 来加载所有环境变量,而不管是否有
// `VITE_` 前缀。
const env = loadEnv ( mode , process . cwd ( ) + "/env" , 'VITE_' )
// console.log("env = ", env)
return {
plugins : [
vue ( ) ,
vueJsx ( ) ,
vueDevTools ( ) ,
AutoImport ( {
resolvers : [ ElementPlusResolver ( ) ] ,
} ) ,
Components ( {
resolvers : [ ElementPlusResolver ( ) ] ,
} ) ,
] ,
resolve : {
alias : {
'@' : fileURLToPath ( new URL ( './src' , import . meta . url ) )
} ,
} ,
// 处理跨域问题
server : {
port : 3000 ,
proxy : {
"/api/v1" : {
target : env.VITE_SERVER_URL ,
changeOrigin : true ,
}
}
} ,
// 自定义环境变量的目录
envDir : "env"
}
} )