无人机管理后台前端(已迁走)
rain
2025-06-12 0082fa417fb2af9add3406bf05ab3e3e45890c34
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
import { defineConfig, loadEnv } from 'vite';
import { resolve } from 'path';
import createVitePlugins from './vite/plugins';
import postCssPxToRem from 'postcss-pxtorem'
// https://vitejs.dev/config/
export default ({ mode, command }) => {
  const env = loadEnv(mode, process.cwd());
  const { VITE_APP_ENV, VITE_APP_BASE, VITE_APP_URL } = env;
  // 判断是打生产环境包
  const isProd = VITE_APP_ENV === 'production';
 
  // 根据是否生产环境,动态设置压缩配置
  const buildConfig = {
    outDir: 'manage',
    target: 'esnext',
    minify: isProd ? 'terser' : 'esbuild', // 根据环境选择压缩工具
  };
 
  // 如果是生产环境,添加Terser的配置
  if (isProd) {
    buildConfig.terserOptions = {
      compress: {
        drop_console: true, // 删除 console
        drop_debugger: true, // 删除 debugger
      },
      format: {
        comments: false, // 删除所有注释
      },
    };
  }
  return defineConfig({
    base: VITE_APP_BASE,
    define: {
      __VUE_I18N_FULL_INSTALL__: true,
      __VUE_I18N_LEGACY_API__: true,
      __INTLIFY_PROD_DEVTOOLS__: false,
    },
    server: {
      // port: 2888,
      // host: '192.168.1.178',
      proxy: {
        '/api': {
          target: VITE_APP_URL,
          changeOrigin: true,
          rewrite: path => path.replace(/^\/api/, ''),
        },
      },
    },
    resolve: {
      alias: {
        '~': resolve(__dirname, './'),
        '@': resolve(__dirname, './src'),
        components: resolve(__dirname, './src/components'),
        styles: resolve(__dirname, './src/styles'),
        utils: resolve(__dirname, './src/utils'),
      },
    },
    css: {
      postcss: {
        plugins: [
          postCssPxToRem({
            rootValue: 10, // 指定转换基准值,通常是设计稿宽度的1/10
            propList: ['*'], // 可以从px转换为rem的属性,这里是所有属性
            unitPrecision: 5, // 允许REM单位增长到的十进制数
            selectorBlackList: [], // 选择器黑名单,忽略转换的选择器
            replace: true, // 替换包含rem的规则,而不是添加回退
            mediaQuery: false, // 允许在媒体查询中转换px
            minPixelValue: 0 // 设置要替换的最小像素值
          }),
        ]
      }
    },
    plugins: createVitePlugins(env, command === 'build'),
    build: buildConfig,
    optimizeDeps: {
      esbuildOptions: {
        target: 'esnext',
      },
    },
  });
};