index.js 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. import path from 'node:path'
  2. import { globSync } from 'glob'
  3. import dynamicIcons from '../src/assets/icons/dynamic-icons.js'
  4. /**
  5. * @usage 生成icons, 用于 unocss safelist,以支持页面动态渲染自定义图标
  6. */
  7. export function getIcons() {
  8. const feFiles = globSync('src/assets/icons/feather/*.svg', { nodir: true, strict: true })
  9. const meFiles = globSync('src/assets/icons/isme/*.svg', { nodir: true, strict: true })
  10. const feIcons = feFiles.map((filePath) => {
  11. const fileName = path.basename(filePath) // 获取文件名,包括后缀
  12. const fileNameWithoutExt = path.parse(fileName).name // 获取去除后缀的文件名
  13. return `i-fe:${fileNameWithoutExt}`
  14. })
  15. const meIcons = meFiles.map((filePath) => {
  16. const fileName = path.basename(filePath) // 获取文件名,包括后缀
  17. const fileNameWithoutExt = path.parse(fileName).name // 获取去除后缀的文件名
  18. return `i-me:${fileNameWithoutExt}`
  19. })
  20. return [...dynamicIcons, ...feIcons, ...meIcons]
  21. }
  22. /**
  23. * @usage 生成.vue文件路径列表,用于添加菜单时可下拉选择对应的.vue文件路径,防止手动输入报错
  24. */
  25. export function getPagePathes() {
  26. const files = globSync('src/views/**/*.vue')
  27. return files.map(item => `/${path.normalize(item).replace(/\\/g, '/')}`)
  28. }