import type { ConfigEnv, UserConfig } from 'vite' import path from 'node:path' import process from 'node:process' import { loadEnv } from 'vite' import { createVitePlugins } from './build/vite' import { exclude, include } from './build/vite/optimize' export default ({ mode }: ConfigEnv): UserConfig => { const root = process.cwd() const env = loadEnv(mode, root) const appProxys = {} const v4Server = 'http://192.168.50.67:31567' const v3Server = 'http://192.168.50.67:31567' const OSSServerDev = 'http://192.168.50.67:30351' const geoserver = 'http://39.104.49.8:30372' const mockServer = 'http://127.0.0.1:8086' // const OSSServerProd = 'http://192.168.50.67:31351' return { base: env.VITE_APP_PUBLIC_PATH, plugins: createVitePlugins(mode), server: { host: true, port: 7190, allowedHosts: [ 'www.aofengcloud.com', '.aofengcloud.com', ], proxy: Object.assign({ // '/api/af-system/user': { // target: 'http://127.0.0.1:9002/', // rewrite: (path: string) => path.replace(/^\/api\/af-system\//, '/'), // ws: false, // changeOrigin: true, // }, '/api/invoice': { target: 'http://219.153.176.6:8400/', rewrite: (path: string) => path.replace(/^\/api\//, '/'), ws: false, changeOrigin: true, }, '/api/af-system/entity/t_files': { target: v3Server, ws: false, changeOrigin: true, }, '/resource': { // pathRewrite: { '^/resource': '/' }, target: v4Server, changeOrigin: true, }, // '/api/af-auth/login': { // target: 'http://127.0.0.1:9200/', // rewrite: (path: string) => path.replace(/^\/api\/af-auth\//, '/'), // ws: false, // changeOrigin: true, // }, // geoserver 转发 '/linepatrol/geoserver': { target: geoserver, changeOrigin: true, rewrite: path => path.replace(/^\/linepatrol\/geoserver/, '/geoserver'), }, // MateChat 聊天 API 代理 '/api/fastApi': { rewrite: (path: string) => path.replace(/^\/api\/fastApi/, '/api'), target: 'http://k8s.aofengcloud.com:32202', ws: false, changeOrigin: true, }, '/api': { // v3用 // rewrite: (path: string) => path.replace(/^\/api\/af-system\//, '/rs/'), target: v4Server, ws: false, changeOrigin: true, }, '/oss': { target: OSSServerDev, rewrite: (path: string) => path.replace(/^\/oss\//, '/'), changeOrigin: true, }, }, appProxys), }, resolve: { alias: { '@': path.join(__dirname, './src'), '~': path.join(__dirname, './src/assets'), '~root': path.join(__dirname, '.'), '@af-mobile-client-vue3': path.join(__dirname, './src'), 'xml-utils': path.resolve(__dirname, 'node_modules/xml-utils'), }, }, build: { cssCodeSplit: false, chunkSizeWarningLimit: 2048, outDir: `./dist/${env.VITE_APP_OUT_DIR}`, rollupOptions: { output: { // 打包时分割资源 chunkFileNames: 'static/js/[name]-[hash].js', entryFileNames: 'static/js/[name]-[hash].js', assetFileNames: 'static/[ext]/[name]-[hash].[ext]', manualChunks(id) { if (id.includes('node_modules')) return 'third' // 代码分割为第三方包 if (id.includes('views')) return 'views' // 代码分割为业务视图 }, }, }, }, optimizeDeps: { include, exclude }, } }