import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import AutoImport from 'unplugin-auto-import/vite' import Components from 'unplugin-vue-components/vite' import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' import path from 'path' // https://vite.dev/config/ export default defineConfig({ plugins: [ vue(), AutoImport({ resolvers: [ElementPlusResolver()], }), Components({ resolvers: [ElementPlusResolver()], }), ], resolve: { // 配置路径别名 alias: { '@': path.resolve(__dirname, 'src'), 'views': '@/views', 'assets': '@/assets', 'common': '@/common', 'components': '@/components', 'network': '@/network', 'router': '@/router', 'store': '@/store' }, // 省略文件后缀 extensions: ['', '.js', '.json', '.vue', '.scss', '.css'] }, // 代理配置 server: { // https: true, port:3000, proxy: { '/api': { // 配置需要代理的路径 --> 这里的意思是代理http://localhost:80/api/后的所有路由 target: 'http://localhost:8888', // 目标地址 --> 服务器地址 changeOrigin: true, // 允许跨域 ws: true, // 允许websocket代理 // 重写路径 --> 作用与vue配置pathRewrite作用相同 rewrite: (path) => path.replace(/^\/api/, "") } }, }, })