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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
| import {
| defineConfig,
| loadEnv
| } from 'vite'
| import { resolve } from 'path'
| import createVitePlugins from './vite/plugins'
| import postCssPxToRem from 'postcss-pxtorem'
| import { fileURLToPath, URL } from "node:url"
|
| import fs from 'fs'
|
| // https://vitejs.dev/config/
| export default ({
| mode,
| command
| }) => {
| const env = loadEnv(mode, fileURLToPath(new URL("./env", import.meta.url)))
|
| const {
| VITE_APP_ENV,
| VITE_APP_BASE,
| VITE_APP_API_URL,
| VITE_APP_RECTANGLE,
| VITE_APP_ARCGIS_URL,
| VITE_APP_MAP_TILE_URL,
| VITE_APP_SEARCH_URL
| } = env
| // 判断是打生产环境包
| const isProd = VITE_APP_ENV === 'production'
|
| // 根据是否生产环境,动态设置压缩配置
| const buildConfig = {
| target: 'esnext',
| minify: isProd ? 'terser' : 'esbuild', // 根据环境选择压缩工具
| }
|
| // 如果是生产环境,添加Terser的配置
| if (isProd) {
| buildConfig.terserOptions = {
| compress: {
| drop_console: true, // 删除 console
| drop_debugger: true, // 删除 debugger
| },
| format: {
| comments: false // 删除所有注释
| }
| }
| buildConfig.rollupOptions = {
| output: {
| manualChunks: {
| 'element-plus': ['element-plus'],
| '@smallwei/avue': ['@smallwei/avue']
| },
| }
| }
| }
| return defineConfig({
| base: VITE_APP_BASE,
| envDir: "./env",
| define: {
| __VUE_I18N_FULL_INSTALL__: true,
| __VUE_I18N_LEGACY_API__: true,
| __INTLIFY_PROD_DEVTOOLS__: false
| },
| server: {
| // https: {
| // key: fs.readFileSync('./127.0.0.1+3-key.pem'), // 私钥路径
| // cert: fs.readFileSync('./127.0.0.1+3.pem'), // 证书路径
| // },
| port: 5179,
| proxy: {
| '/aisky-webodm-vol': {
| target: 'https://wrj.shuixiongit.com/aisky-webodm-vol',
| changeOrigin: true,
| rewrite: path => path.replace(/^\/aisky-webodm-vol/, ''),
| },
|
| '/droneAppCustomServer': {
| target: 'http://t1.tianditu.com',
| changeOrigin: true,
| rewrite: path => path.replace(/^\/droneAppCustomServer/, ''),
| },
|
| '/restapi-amap': {
| target: VITE_APP_SEARCH_URL,
| changeOrigin: true,
| rewrite: path => path.replace(/^\/restapi-amap/, ''),
| },
|
| '/webodm-vol': {
| target: 'https://wrj.shuixiongit.com/webodm-vol',
| changeOrigin: true,
| rewrite: path => path.replace(/^\/webodm-vol/, ''),
| },
|
| '/3Dtile': {
| target: VITE_APP_MAP_TILE_URL,
| changeOrigin: true,
| rewrite: path => path.replace(/^\/3Dtile/, ''),
| },
|
| '/arcgis116': {
| target: VITE_APP_ARCGIS_URL,
| changeOrigin: true,
| rewrite: path => path.replace(/^\/arcgis116/, ''),
| },
|
| '/dji_in_rectangle': {
| target: VITE_APP_RECTANGLE,
| changeOrigin: true,
| rewrite: path => path.replace(/^\/dji_in_rectangle/, ''),
| },
|
| '/api': {
| target: VITE_APP_API_URL,
| changeOrigin: true,
| rewrite: path => path.replace(/^\/api/, ''),
| }
| },
| },
| assetsInclude: ['**/*.gltf'],
| resolve: {
| alias: {
| '~': resolve(__dirname, './'),
| '@': resolve(__dirname, './src'),
| components: resolve(__dirname, './src/components'),
| styles: resolve(__dirname, './src/styles'),
| utils: resolve(__dirname, './src/utils'),
| },
| },
| css: {
| preprocessorOptions: {
| scss: {
| api: 'modern-compiler',
| additionalData: `@use "@/styles/variables.scss" as *;`,
| },
| },
| 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',
| },
| },
| })
| }
|
|