cmvr-wms/ruoyi-ui-vue3/vite/plugins/element-icons.js
lixiaolong e78ed25668 refactor(components): 优化组件交互和数据验证逻辑
- 为对话框添加防止意外关闭的安全措施
- 实现表单提交时的数据有效性验证
- 集成远程选择器组件提升用户体验
- 更新表格组件样式适配新设计规范
- 优化列表页面加载和错误处理机制
- 统一组件尺寸设置和存储管理
2026-10-14 09:11:33 +08:00

38 lines
1.8 KiB
JavaScript

import fs from 'node:fs'
import path from 'node:path'
import * as icons from '@element-plus/icons-vue'
// Statically used icons are tree-shaken named imports. All other names remain
// registered as lazy fallbacks so menu/config-driven icons continue to work.
export default function elementIcons() {
const id = 'virtual:business-element-icons'
let root
function collect(directory) {
return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
const file = path.join(directory, entry.name)
return entry.isDirectory() ? collect(file) : /\.(vue|js)$/.test(file) ? [fs.readFileSync(file, 'utf8')] : []
}).join('\n')
}
return {
name: 'business-element-icons',
configResolved(config) { root = config.root },
resolveId(source) { if (source === id) return '\0' + id },
load(source) {
if (source !== '\0' + id) return
const text = collect(path.join(root, 'src'))
const names = Object.keys(icons)
const used = names.filter(name => {
const kebab = name.replace(/[A-Z]/g, (letter, index) => (index ? '-' : '') + letter.toLowerCase())
return new RegExp(`(?:<|["'])(${name}|${kebab})(?:[\\s/>"'])`).test(text)
})
return `import { defineAsyncComponent } from 'vue';\n` +
`import { ${used.join(',')} } from '@element-plus/icons-vue';\n` +
`const components = { ${used.join(',')} };\n` +
// The separate official distribution keeps the fallback out of the
// eager named-import module (Rollup otherwise merges both into entry).
`for (const name of ${JSON.stringify(names.filter(name => !used.includes(name)))}) components[name] = defineAsyncComponent(() => import('@element-plus/icons-vue/global').then(icons => icons[name]));\n` +
`export default components;`
}
}
}