智慧园区前端大屏
shuishen
2025-01-15 548dcb58164aaeb7ec8a4f3425953bcd25d83c65
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2024-10-25 10:56:27
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2024-12-17 12:07:31
 * @FilePath: \bigScreen\vite.config.js
 * @Description: 
 * 
 * Copyright (c) 2024 by shuishen, All Rights Reserved. 
 */
import { defineConfig, loadEnv } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
import DC from "@dvgis/vite-plugin-dc"
 
import AutoImport from 'unplugin-auto-import/vite'
import basicSsl from '@vitejs/plugin-basic-ssl'
import { fa } from 'element-plus/es/locales.mjs'
import viteCompression from 'vite-plugin-compression'
// import vueDevTools from 'vite-plugin-vue-devtools'
 
export default ({ mode, command }) => {
  const env = loadEnv(mode, process.cwd())
  const { VITE_APP_ENV, VITE_APP_BASE } = env
  // 判断是打生产环境包
  const isProd = VITE_APP_ENV === 'production'
 
  // 根据是否生产环境,动态设置压缩配置
  const buildConfig = {
    outDir: 'zhyq',
    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,
    build: buildConfig,
 
    plugins: [
      vue(),
      DC(),
      basicSsl(),
      AutoImport({
        imports: ["vue", "vue-router"], // 自动导入vue和vue-router相关函数
      }),
      viteCompression({
        filter: /\.(js|css|json|txt|ico|svg)(\?.*)?$/i, // 需要压缩的文件
        threshold: 1024, // 文件容量大于这个值进行压缩
        algorithm: 'gzip', // 压缩方式
        ext: 'gz', // 后缀名
        deleteOriginFile: false, // 压缩后是否删除压缩源文件
      }),
      // vueDevTools()
    ],
 
    css: {
      preprocessorOptions: {
        scss: {
          api: 'modern-compiler', // 修改api调用方式
          additionalData: `@use "@/styles/variables.scss" as *;`
        }
      }
    },
 
    resolve: {
      alias: {
        '~': resolve(__dirname, './'),
        '@': resolve(__dirname, './src'),
        components: resolve(__dirname, './src/components'),
        styles: resolve(__dirname, './src/styles'),
        utils: resolve(__dirname, './src/utils'),
        store: resolve(__dirname, './src/store'),
        hooks: resolve(__dirname, './src/hooks'),
      },
    },
 
    server: {
      port: 668,
      https: true,
      host: '0.0.0.0',
      // hmr:{
      //   overlay:false
      // },
      proxy: {
        '/xinganTileset': {
          // target: 'http://localhost',
          target: 'http://182.109.88.42:10010/xinganTileset',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/xinganTileset/, ''),
        },
 
        '/zhyq3Dtile': {
          // target: 'http://localhost',
          target: 'https://wrj.shuixiongit.com/zhyq3Dtile',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/zhyq3Dtile/, ''),
        },
 
        '/panorama': {
          // target: 'http://localhost',
          target: 'http://vr.jxpskj.com:180',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/panorama/, ''),
        },
 
        '/zhyq-xg/newMx': {
          // target: 'http://localhost',
          target: 'https://wrj.shuixiongit.com/zhyq-xg/newMx',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/zhyq-xg\/newMx/, ''),
        },
 
        // '/zhyq-xg/mx': {
        //   // target: 'http://localhost',
        //   target: 'https://wrj.shuixiongit.com/zhyq-xg/mx',
        //   changeOrigin: true,
        //   rewrite: path => path.replace(/^\/zhyq-xg\/mx/, ''),
        // },
 
        '/zhyqapi': {
          // target: 'http://localhost:8082',
          target: 'https://wrj.shuixiongit.com/zhyqapi',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/zhyqapi/, ''),
        },
      },
    },
  })
}
// https://vite.dev/config/