59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
import { fileURLToPath, URL } from 'node:url'
|
|
|
|
import { defineConfig } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import vueDevTools from 'vite-plugin-vue-devtools'
|
|
|
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
import Components from 'unplugin-vue-components/vite'
|
|
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
import { loadEnv } from 'vite'
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig(({ mode, command }) => {
|
|
const env = loadEnv(mode, process.cwd())
|
|
const { VITE_APP_ENV, VITE_APP_BASE_URL,VITE_APP_BASE_URL_WS} = env
|
|
return {
|
|
plugins: [
|
|
vue(),
|
|
vueDevTools(),
|
|
AutoImport({
|
|
resolvers: [ElementPlusResolver()],
|
|
}),
|
|
Components({
|
|
resolvers: [ElementPlusResolver()],
|
|
}),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
|
},
|
|
},
|
|
|
|
// vite 相关配置
|
|
server: {
|
|
port: 5173,
|
|
host: true,
|
|
open: false,
|
|
|
|
|
|
proxy: {
|
|
// https://cn.vitejs.dev/config/#server-proxy
|
|
'/api': {
|
|
target: VITE_APP_BASE_URL,
|
|
changeOrigin: true,
|
|
rewrite: (p) => p.replace(/^\/api/, ''),
|
|
},
|
|
|
|
// '/dev-ws': {
|
|
// target: VITE_APP_BASE_URL_WS,
|
|
// changeOrigin: true,
|
|
// rewrite: (p) => p.replace(/^\/dev-ws/, ''),
|
|
// ws: true
|
|
// }
|
|
|
|
}
|
|
},
|
|
}
|
|
})
|