WholeProcessPlatform/frontend-sjgl/vite.config.ts
2026-08-31 14:30:58 +08:00

164 lines
5.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { UserConfig, ConfigEnv, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import path from 'path';
export default ({ mode }: ConfigEnv): UserConfig => {
// 获取 .env 环境配置文件
const env = loadEnv(mode, process.cwd());
return {
plugins: [
vue(),
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地址
target: env.VITE_APP_BASE_URL,
// 本地API地址
// target: 'http://10.84.121.21:8093',
changeOrigin: true,
rewrite: path =>
path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '')
},
'/process': {
target: 'http://localhost:5174',
changeOrigin: true
},
'/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'
)
},
'/wmp-env-server': {
target: 'https://211.99.26.225:12122',
changeOrigin: true,
secure: false,
rewrite: path =>
path.replace(new RegExp('^/wmp-env-server'), '/api/wmp-env-server')
},
'/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'
)
},
'/api/wmp-eng-server': {
target: 'https://211.99.26.225:12122',
changeOrigin: true,
secure: false,
rewrite: path =>
path.replace(
new RegExp('^/api/wmp-eng-server'),
'/api/wmp-eng-server'
)
},
'/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'
)
},
'/api/dec-modules-usm-springcloud-starter': {
target: 'https://211.99.26.225:12122',
changeOrigin: true,
secure: false,
rewrite: path =>
path.replace(
new RegExp('^/api/dec-modules-usm-springcloud-starter'),
'/api/dec-modules-usm-springcloud-starter'
)
},
'/api/wmp-swqx-server/': {
target: 'https://211.99.26.225:12122',
changeOrigin: true,
secure: false,
rewrite: path =>
path.replace(
new RegExp('^/api/dec-modules-usm-springcloud-starter'),
'/api/dec-modules-usm-springcloud-starter'
)
}
// /
}
},
build: {
// 1. 增加 chunk 大小警告限制(避免过多小文件)
chunkSizeWarningLimit: 1000,
// 2. 优化 Rollup 配置
rollupOptions: {
output: {
// 手动分块,将大型库单独打包,减少单个 chunk 的复杂度
manualChunks(id) {
if (id.includes('node_modules')) {
// 将 univer 相关包统一归为单个 chunk避免同套模块被打散成多份
if (id.includes('@univerjs')) return 'univer';
// 将 element-plus, lodash 等大型库单独拆分
if (id.includes('element-plus')) return 'element-plus';
if (id.includes('ant-design-vue')) return 'ant-design-vue';
if (id.includes('lodash')) return 'lodash';
// 其他 node_modules 归为 vendor
return 'vendor';
}
}
}
}
},
// 预构建 univer 相关依赖,避免 dev 下同一模块被浏览器按多个 chunk 重复加载
optimizeDeps: {
include: [
'@univerjs/core',
'@univerjs/presets',
'@univerjs/preset-sheets-core',
'@univerjs-pro/exchange-client'
]
},
resolve: {
// 确保 univer 相关包只解析一份副本,防止多版本副本导致 DI 标识符重复
dedupe: [
'@univerjs/core',
'@univerjs/presets',
'@univerjs/preset-sheets-core',
'@univerjs-pro/exchange-client'
],
// Vite路径别名配置
alias: {
'@': path.resolve(__dirname, './src')
}
},
css: {
preprocessorOptions: {
scss: {
silenceDeprecations: ['legacy-js-api'],
api: 'modern-compiler' // 使用现代API
}
}
}
};
};