- 新增 useTabOrder、tab-order 工具与 tab-order-registry 注册表,按模块集中登记 页面标签并懒加载默认标签;新增 TabOrderSettingsDialog、TabOrderDragList, 支持拖拽排序、设置默认页签与重置,SortSettingDialog / TabArea 迁移到同一套实现 - 用户偏好存储新增「用户级」globalMap(不随仓库隔离),tabOrder 写入用户级 scope, 旧 scope 一次性迁移并对齐回退读取;各页面 config 接入统一注册表, 移除页面内自写的排序与默认页签逻辑 - 新增 tbyc-config 统一配置文件与分区注册表,UpperTable 的配置导出/导入 升级为 tbyc-config.json(字段列、标签排序、界面显示、快捷键), 兼容旧版「全局字段配置」与 tabOrders 文件 - Element Plus 改为 unplugin-vue-components 按需自动引入,移除 app.use(ElementPlus)、dts 生成与强制 vendor-element-plus 分包 - ECharts 改为按需注册(折线/饼图 + 所需组件),dashboard 图表统一走 @/utils/echarts;移除 three.js 及 overlookControls / threeScene / threeUtils, 同步清理依赖、manualChunks 与 optimizeDeps - vue-devtools 支持 VITE_VUE_DEVTOOLS=off 关闭;抽离 wavePrintPayload 供订单、 复核页面复用,scanFields 承接批量搜索操作符与「包含商品」筛选项 - 补充标签排序与默认页签统一方案、tbyc-config 说明文档, 更新标签页性能测量结论与用户偏好保存方案
144 lines
6.2 KiB
TypeScript
144 lines
6.2 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url'
|
||
import path from 'path'
|
||
import { defineConfig, loadEnv } from 'vite'
|
||
import vue from '@vitejs/plugin-vue'
|
||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
||
import Components from 'unplugin-vue-components/vite'
|
||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||
import { COS_DEV_PROXY_PREFIX, COS_DEV_PROXY_OFF, DEFAULT_COS_DEV_PROXY_TARGET } from './src/utils/cosDevProxyConfig'
|
||
|
||
// https://vite.dev/config/
|
||
export default defineConfig(({ mode }) => {
|
||
const env = loadEnv(mode, process.cwd(), 'VITE_')
|
||
|
||
// 本地开发:浏览器直传对象存储会被跨域(CORS)拦截,这里挂一条同源代理绕过。
|
||
// 仅 dev server 生效,生产构建/部署不包含该代理。
|
||
const cosProxyEnabled = env.VITE_COS_DEV_PROXY !== COS_DEV_PROXY_OFF
|
||
const cosProxyTarget = env.VITE_COS_DEV_PROXY_TARGET || DEFAULT_COS_DEV_PROXY_TARGET
|
||
const cosProxyPrefixRe = new RegExp(`^${COS_DEV_PROXY_PREFIX}`)
|
||
|
||
// vue-devtools 仅开发期生效,但会给 dev 页面注入约 3MB 的 overlay / devtools-kit 模块。
|
||
// 需要干净的性能基线时,启动前设置环境变量 VITE_VUE_DEVTOOLS=off 即可关闭(生产构建本来就不包含)。
|
||
const devtoolsEnabled = env.VITE_VUE_DEVTOOLS !== 'off'
|
||
|
||
return {
|
||
plugins: [
|
||
vue(),
|
||
...(devtoolsEnabled ? [vueDevTools()] : []),
|
||
/**
|
||
* Element Plus 按需引入:模板里的 <el-xxx> 与 v-loading 等指令自动按需 import,
|
||
* 不再依赖 main.ts 的 app.use(ElementPlus) 全量注册(后者会把全部组件打进一个 chunk)。
|
||
* importStyle 先关掉:全量样式仍在 main.ts 引入,避免漏样式导致的视觉回归。
|
||
*/
|
||
Components({
|
||
// dts 先关:开启后会给 <el-*> 带上严格 props 类型,会暴露 113 处历史宽松写法(:type="字符串变量" 等),
|
||
// 与本次性能优化无关,留待单独清理。运行期按需引入不受影响。
|
||
dts: false,
|
||
directives: true,
|
||
resolvers: [ElementPlusResolver({ importStyle: false })]
|
||
}),
|
||
createSvgIconsPlugin({
|
||
// Specify the icon folder to be cached
|
||
iconDirs: [path.resolve(process.cwd(), 'src/icons/svg')],
|
||
// Specify symbolId format
|
||
symbolId: 'icon-[dir]-[name]',
|
||
}),
|
||
],
|
||
server: {
|
||
port: 5174,
|
||
host: '0.0.0.0',
|
||
// 允许所有主机访问开发服务器(如 test.wms.com、局域网 IP 等)
|
||
allowedHosts: true,
|
||
proxy: {
|
||
'/dev-api': {
|
||
target: 'http://localhost:9528', // Assuming Vue 2 backend is running here, user can change
|
||
changeOrigin: true,
|
||
rewrite: (path) => path.replace(/^\/dev-api/, '')
|
||
},
|
||
'/dl-api': {
|
||
target: 'https://dl.wms.gztbyc.com',
|
||
changeOrigin: true,
|
||
rewrite: (path) => path.replace(/^\/dl-api/, '')
|
||
},
|
||
// 海康 SDK ISAPI 请求 → 本地代理 → NVR
|
||
'/ISAPI': {
|
||
target: 'http://localhost:17311',
|
||
changeOrigin: true
|
||
},
|
||
// 对象存储直传同源代理:/cos-proxy/<原路径> → <存储桶>/<原路径>
|
||
// 把浏览器直传变成同源请求,绕过存储桶 CORS 白名单限制(详见 src/utils/cosDevProxyConfig.ts)
|
||
...(cosProxyEnabled
|
||
? {
|
||
[COS_DEV_PROXY_PREFIX]: {
|
||
target: cosProxyTarget,
|
||
changeOrigin: true,
|
||
secure: true,
|
||
rewrite: (path) => path.replace(cosProxyPrefixRe, '') || '/',
|
||
configure: (proxy) => {
|
||
// 去掉浏览器带来的 Origin / Referer,避免存储桶按 CORS 规则判定请求
|
||
proxy.on('proxyReq', (proxyReq) => {
|
||
proxyReq.removeHeader('origin')
|
||
proxyReq.removeHeader('referer')
|
||
})
|
||
}
|
||
}
|
||
}
|
||
: {})
|
||
}
|
||
},
|
||
resolve: {
|
||
alias: {
|
||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||
},
|
||
},
|
||
/**
|
||
* echarts 按需引入后会新增若干子路径依赖(echarts/core、echarts/charts…)。
|
||
* 预构建它们,避免首次访问 dashboard 时 Vite 触发「Outdated Optimize Dep」并强制整页刷新。
|
||
*/
|
||
optimizeDeps: {
|
||
include: [
|
||
'echarts/core',
|
||
'echarts/charts',
|
||
'echarts/components',
|
||
'echarts/features',
|
||
'echarts/renderers'
|
||
]
|
||
},
|
||
build: {
|
||
// 单库 chunk 本身就可能超 500kB(echarts / element-plus 全量引入),阈值按实际基线设置
|
||
chunkSizeWarningLimit: 1200,
|
||
rollupOptions: {
|
||
output: {
|
||
/**
|
||
* 按库拆分第三方依赖,避免全量 element-plus / echarts 等挤进入口 chunk
|
||
* (入口曾达 3.9MB)。拆成独立 chunk 后可并行加载,且升级应用代码时第三方 chunk 哈希不变、命中长期缓存。
|
||
*/
|
||
manualChunks(id) {
|
||
if (!id.includes('node_modules')) return
|
||
if (id.includes('echarts') || id.includes('zrender')) return 'vendor-echarts'
|
||
if (id.includes('xlsx')) return 'vendor-xlsx'
|
||
// element-plus 不再强制合并成一个 chunk:按需引入后由 rollup 按实际使用自然拆分,
|
||
// 否则仍会把全部组件塞进同一个首屏 chunk,按需引入等于没做。
|
||
if (id.includes('china-division')) return 'vendor-china-division'
|
||
if (
|
||
id.includes('/vue/') ||
|
||
id.includes('/vue-') ||
|
||
id.includes('/@vue/') ||
|
||
id.includes('/pinia') ||
|
||
id.includes('@vueuse')
|
||
) {
|
||
// 含 vue-demi / vue-router / vue-i18n / vue-draggable-plus / pinia 等所有依赖 vue 的库,
|
||
// 否则这些库落到 vendor 会与 vendor-vue 形成循环 chunk
|
||
return 'vendor-vue'
|
||
}
|
||
// 其余第三方模块不再强制归入单一 vendor chunk:
|
||
// 否则一个 catch-all chunk 会把「只有某个懒加载页才用到」的库也塞进首屏。
|
||
return undefined
|
||
}
|
||
}
|
||
}
|
||
},
|
||
}
|
||
})
|