Bang Hu
2025-08-29 e1f9a259750f387fbaa4b60295f42eaf9b74cfd8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import vue from '@vitejs/plugin-vue'
import * as path from 'path' // node的path路径引用
import { resolve } from 'path'
import type { UserConfig, ConfigEnv, ProxyOptions } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Icons from 'unplugin-icons/vite'
import { FileSystemIconLoader } from 'unplugin-icons/loaders'
import IconsResolver from 'unplugin-icons/resolver'
import Components from 'unplugin-vue-components/vite'
import { svgBuilder } from './src/utils/svgBuilder'
 
const pathResolve = (dir: string): any => {
  return resolve(__dirname, '.', dir)
}
// https://vitejs.cn/config/
const viteConfig = ({ mode }: ConfigEnv): UserConfig => {
  let proxy: Record<string, string | ProxyOptions> = {}
  proxy = {
    '/api/report': {
      target: 'http://36.133.126.111:7099',
      changeOrigin: true,
      // rewrite: (path) => path.replace(/^\/api/, '/'),
    },
    '/api': {
      // target: 'http://192.168.0.38:8088', // 李
      // target: 'http://10.88.211.191:8088', // 李
      // target:'http://10.209.233.16/admin',//信创正式
      // target: 'http://36.133.126.111:7099/api', //测试
      // target: 'https://zynlpt.ccccltd.cn/admin', // 正式  (要打开changeOrigin和rewrite)
      //    target: 'http://localhost:8080',
         target: 'http://36.133.126.111:7099/trade-api',
      changeOrigin: true, // 允许跨域
      rewrite: (path) => path.replace(/^\/api/, '/'), //连测试环境要注释这行,连后端个人则打开
    },
  }
  return {
    plugins: [
      vue(),
      AutoImport({
        resolvers: [
          ElementPlusResolver(),
          IconsResolver({
            prefix: 'Icon',
          }),
        ],
        imports: ['vue', 'vue-router', 'pinia'],
        dts: 'src/auto-import.d.ts',
        eslintrc: {
          enabled: true, // Default `false`
          filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
          globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
        },
      }),
      svgBuilder('./src/assets/icons/svg/'),
      Components({
        resolvers: [
          ElementPlusResolver(),
          IconsResolver({
            enabledCollections: ['ep'],
          }),
        ],
      }),
      Icons({
        autoInstall: true,
        compiler: 'vue3',
        customCollections: {
          // 这里是存放svg图标的文件地址,svg是自定义图标库的名称
          custom: FileSystemIconLoader('./src/assets/icons/svg'),
        },
      }),
    ],
    root: process.cwd(),
    // resolve: { alias },
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src'),
      },
    },
    base: '/trade/',
    server: {
      host: '0.0.0.0',
      port: 1000,
      open: true,
      proxy: proxy,
    },
    build: {
      sourcemap: false,
      outDir: 'dist',
      emptyOutDir: true,
      chunkSizeWarningLimit: 1500,
      minify: 'terser',
      terserOptions: {
        //打包后移除console和注释
        compress: {
          drop_console: false,
          drop_debugger: true,
        },
      },
    },
    // css: {
    //     preprocessorOptions: {
    //         scss: {
    //             additionalData: `@import "@/styles/var.scss";`
    //         }
    //     }
    // }
  }
}
 
export default viteConfig