12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import { fileURLToPath, URL } from 'node:url'
- import { defineConfig, loadEnv } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import vueDevTools from 'vite-plugin-vue-devtools'
- import Components from 'unplugin-vue-components/vite'
- import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
- // https://vite.dev/config/
- export default defineConfig(({ mode }) => {
- // 加载环境变量
- const env = loadEnv(mode, process.cwd(), '')
- // 获取当前环境的API主机
- const apiHost = env.VITE_APP_HOST
- // 添加日志输出
- console.log(`🚀CurrentMode: ${mode}`)
- console.log(`🚀HostAPI: ${apiHost}`)
- console.log(`🚀ProxyAPI: ${apiHost}`)
- return {
- plugins: [
- vue(),
- vueDevTools(),
- Components({
- resolvers: [
- AntDesignVueResolver({
- importStyle: false, // css in js
- }),
- ],
- }),
- ],
- resolve: {
- alias: {
- '@': fileURLToPath(new URL('./src', import.meta.url)),
- },
- },
- server: {
- proxy: {
- '/portal-service-server': {
- target: apiHost,
- changeOrigin: true,
- secure: false,
- rewrite: (path) => path,
- },
- '/pub': {
- target: apiHost,
- changeOrigin: true,
- secure: false,
- rewrite: (path) => path,
- },
- },
- cors: true,
- },
- }
- })
|