2026-03-25 10:02:19 +08:00
|
|
|
import { UserConfig, ConfigEnv, loadEnv } from 'vite';
|
|
|
|
|
import vue from '@vitejs/plugin-vue';
|
|
|
|
|
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
|
|
|
|
|
import path from 'path';
|
2026-05-15 17:38:03 +08:00
|
|
|
import cesium from 'vite-plugin-cesium';
|
2026-03-25 10:02:19 +08:00
|
|
|
|
|
|
|
|
export default ({ mode }: ConfigEnv): UserConfig => {
|
|
|
|
|
// 获取 .env 环境配置文件
|
|
|
|
|
const env = loadEnv(mode, process.cwd());
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
plugins: [
|
|
|
|
|
vue(),
|
2026-05-15 17:38:03 +08:00
|
|
|
cesium(),
|
2026-03-25 10:02:19 +08:00
|
|
|
createSvgIconsPlugin({
|
|
|
|
|
// 指定需要缓存的图标文件夹
|
|
|
|
|
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
|
|
|
|
|
// 指定symbolId格式
|
|
|
|
|
symbolId: 'icon-[dir]-[name]'
|
|
|
|
|
})
|
|
|
|
|
],
|
|
|
|
|
// 本地反向代理解决浏览器跨域限制
|
|
|
|
|
server: {
|
|
|
|
|
host: '0.0.0.0',
|
|
|
|
|
port: Number(env.VITE_APP_PORT),
|
|
|
|
|
open: true, // 运行自动打开浏览器
|
|
|
|
|
proxy: {
|
|
|
|
|
[env.VITE_APP_BASE_API]: {
|
|
|
|
|
// 线上API地址
|
2026-04-28 19:27:42 +08:00
|
|
|
target: env.VITE_APP_BASE_URL,
|
2026-03-25 10:02:19 +08:00
|
|
|
// 本地API地址
|
2026-04-28 19:27:42 +08:00
|
|
|
// target: 'http://10.84.121.21:8093',
|
2026-03-25 10:02:19 +08:00
|
|
|
changeOrigin: true,
|
|
|
|
|
rewrite: path =>
|
|
|
|
|
path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
|
2026-03-25 17:32:09 +08:00
|
|
|
},
|
2026-04-20 16:57:54 +08:00
|
|
|
'/geoserver': {
|
2026-05-15 17:38:03 +08:00
|
|
|
target: 'https://211.99.26.225:18085', // 地图-线上API地址
|
2026-05-12 08:47:27 +08:00
|
|
|
// target: 'http://172.16.31.112:8093', // 地图-本地API地址
|
2026-04-20 16:57:54 +08:00
|
|
|
changeOrigin: true,
|
|
|
|
|
secure: false,
|
|
|
|
|
rewrite: path => path.replace(new RegExp('^/geoserver'), '/geoserver')
|
|
|
|
|
},
|
2026-03-25 17:32:09 +08:00
|
|
|
'/process': {
|
|
|
|
|
target: 'http://localhost:5174',
|
|
|
|
|
changeOrigin: true
|
2026-05-15 17:38:03 +08:00
|
|
|
},
|
|
|
|
|
'/api/dec-lygk-base-server': {
|
|
|
|
|
target: 'https://211.99.26.225:12122',
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
secure: false,
|
|
|
|
|
rewrite: path =>
|
|
|
|
|
path.replace(
|
|
|
|
|
new RegExp('^/api/dec-lygk-base-server'),
|
|
|
|
|
'/api/dec-lygk-base-server'
|
|
|
|
|
)
|
2026-05-19 18:56:33 +08:00
|
|
|
},
|
|
|
|
|
'/api/wmp-env-server': {
|
|
|
|
|
target: 'https://211.99.26.225:12122',
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
secure: false,
|
|
|
|
|
rewrite: path =>
|
|
|
|
|
path.replace(
|
|
|
|
|
new RegExp('^/api/wmp-env-server'),
|
|
|
|
|
'/api/wmp-env-server'
|
|
|
|
|
)
|
2026-05-20 17:55:48 +08:00
|
|
|
},
|
|
|
|
|
'/api/wmp-sys-server': {
|
|
|
|
|
target: 'https://211.99.26.225:12122',
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
secure: false,
|
|
|
|
|
rewrite: path =>
|
|
|
|
|
path.replace(
|
|
|
|
|
new RegExp('^/api/wmp-sys-server'),
|
|
|
|
|
'/api/wmp-sys-server'
|
|
|
|
|
)
|
2026-03-25 10:02:19 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-04-22 17:53:20 +08:00
|
|
|
build: {
|
|
|
|
|
// 1. 增加 chunk 大小警告限制(避免过多小文件)
|
|
|
|
|
chunkSizeWarningLimit: 1000,
|
|
|
|
|
|
|
|
|
|
// 2. 优化 Rollup 配置
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
output: {
|
|
|
|
|
// 手动分块,将大型库单独打包,减少单个 chunk 的复杂度
|
|
|
|
|
manualChunks(id) {
|
|
|
|
|
if (id.includes('node_modules')) {
|
|
|
|
|
// 将 element-plus, lodash 等大型库单独拆分
|
|
|
|
|
if (id.includes('element-plus')) return 'element-plus';
|
|
|
|
|
if (id.includes('lodash')) return 'lodash';
|
2026-05-15 17:38:03 +08:00
|
|
|
if (id.includes('cesium')) return 'cesium';
|
2026-04-22 17:53:20 +08:00
|
|
|
// 其他 node_modules 归为 vendor
|
|
|
|
|
return 'vendor';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2026-03-25 10:02:19 +08:00
|
|
|
resolve: {
|
|
|
|
|
// Vite路径别名配置
|
|
|
|
|
alias: {
|
2026-03-27 14:50:35 +08:00
|
|
|
'@': path.resolve(__dirname, './src')
|
2026-03-25 10:02:19 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
css: {
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
scss: {
|
|
|
|
|
silenceDeprecations: ['legacy-js-api'],
|
|
|
|
|
api: 'modern-compiler' // 使用现代API
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-03-25 17:32:09 +08:00
|
|
|
};
|