From dev-skills
初始化 vite+vue3 项目的 pure-admin 风格 iconify 图标渲染体系(离线 + 在线 + useRenderIcon 统一渲染)。当用户提及“初始化 iconify”“pure-admin 图标方案”“ReIcon/useRenderIcon”“离线图标接入”“后台项目图标基础设施”时使用此技能。
How this skill is triggered — by the user, by Claude, or both
Slash command
/dev-skills:init-pure-admin-iconifyThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
本技能用于在任意 `vite + vue3` 项目中,快速初始化一套与 pure-admin 思路一致的 iconify 图标体系,提供:
本技能用于在任意 vite + vue3 项目中,快速初始化一套与 pure-admin 思路一致的 iconify 图标体系,提供:
IconifyIconOffline(离线图标)IconifyIconOnline(在线图标)useRenderIcon(统一分流渲染)offlineIcon(本地离线图标映射与兼容别名)目标是让业务层只关心“传什么图标”,不关心底层是离线、在线还是组件对象。
IconXxx 命名,同时支持新式 collection/name、collection:nameComponent 类型图标ReIcon 导出使用,不要各处二次封装 @iconify/vueuseRenderIcon:菜单、路由、表格配置统一返回组件IconXxx 仅做兼容,不作为新代码首选优先使用“照抄 + 最小改造”策略,不要凭记忆重写。
如果已有可运行的 src/components/ReIcon,优先完整复制后做最小改动。
将来源项目 src/components/ReIcon 映射到目标项目同路径:
来源文件 -> 目标文件
src/components/ReIcon/index.ts -> src/components/ReIcon/index.ts
src/components/ReIcon/type.ts -> src/components/ReIcon/type.ts
src/components/ReIcon/src/hooks.ts -> src/components/ReIcon/src/hooks.ts
src/components/ReIcon/src/iconifyIconOffline.ts -> src/components/ReIcon/src/iconifyIconOffline.ts
src/components/ReIcon/src/iconifyIconOnline.ts -> src/components/ReIcon/src/iconifyIconOnline.ts
src/components/ReIcon/src/offlineIcon.ts -> src/components/ReIcon/src/offlineIcon.ts
只复制这 6 个文件即可完成核心能力。
@/ 是否存在main.ts 或 src/plugins/icon.tsofflineIcon.ts 里导入和映射项IconXxx 是否需要保留除上述改动外,不要主动改 API、类型和导出结构。
在目标项目安装:
pnpm add -D @iconify/json @iconify/vue unplugin-icons vite-svg-loader
可选工具:
pnpm add @pureadmin/utils
如果你采用
~icons/...组件导入方式,unplugin-icons是必需项。
在 vite.config.ts(或插件聚合文件)添加 unplugin-icons:
import Icons from "unplugin-icons/vite";
export default defineConfig({
plugins: [
vue(),
Icons({
compiler: "vue3",
scale: 1,
}),
],
});
建议结构:
src/components/ReIcon/
├── index.ts
├── type.ts
└── src/
├── iconifyIconOffline.ts
├── iconifyIconOnline.ts
├── hooks.ts
└── offlineIcon.ts
模板代码已拆分到 templates/ 目录,直接按路径复制,不需要手动从文档里摘代码。
templates/ReIcon/index.ts
templates/ReIcon/type.ts
templates/ReIcon/src/iconifyIconOffline.ts
templates/ReIcon/src/iconifyIconOnline.ts
templates/ReIcon/src/hooks.ts
templates/ReIcon/src/offlineIcon.ts
templates/setup-icon.ts
复制规则:
templates/ReIcon/** -> src/components/ReIcon/**templates/setup-icon.ts -> src/plugins/icon.ts(或合并到你的入口注册文件)如果你希望“一字不动照抄”旧项目,请把旧项目
offlineIcon.ts全量复制过来,再对照模板补齐缺失导出。
在 src/plugins/icon.ts(或等价入口)注册:
import type { App } from "vue";
import { IconifyIconOffline, IconifyIconOnline, registerOfflineIcons } from "@/components/ReIcon";
export function setupIcon(app: App) {
registerOfflineIcons(app);
app.component("IconifyIconOffline", IconifyIconOffline);
app.component("IconifyIconOnline", IconifyIconOnline);
}
如果旧项目已大量使用 Element Plus 全局图标别名,不要删除原注册,只新增 iconify 能力。
<IconifyIconOffline icon="ep/menu" width="18" height="18" />
<IconifyIconOnline icon="ri:home-4-line" width="18" height="18" />
import { useRenderIcon } from "@/components/ReIcon";
const iconComp = useRenderIcon("ep/setting", { width: "18px", height: "18px" });
菜单项 icon 可直接写:
IconUserep/settingri:shield-user-line渲染层统一走 useRenderIcon,不要在菜单组件内部再写一套 icon 分流逻辑。
~icons/... 导入是否生效(未生效通常是漏配 unplugin-icons)@/components/ReIcon 是否可解析registerOfflineIcons(app) 是否在应用启动阶段执行IconXxx,对应 alias 是否存在仅在以下情况扩充 offlineIcon.ts:
useRenderIcon 中稳定命中离线路径扩充步骤:
import EpXxx from "~icons/ep/xxx"offlineIcons["ep/xxx"] = markRaw(EpXxx)aliasIcons.IconXxx = offlineIcons["ep/xxx"]vite.config.ts 已启用 unplugin-iconsReIcon 目录和导出结构完整useRenderIcon 可同时处理组件、离线字符串、在线字符串IconXxx 页面未被破坏.icon-title 这类容易冲突的命名,使用更局部语义类名IconXxx 只保兼容,新代码优先 ep/menu、ri:...、useRenderIconReIcon 再造一套 renderIconReIcon 文件useRenderIconnpx claudepluginhub ruan-cat/monorepo --plugin dev-skillsImplements scalable icon systems with SVG sprites or React/Vue components. Use when setting up icon libraries, creating icon sizing tokens, optimizing SVGs, or building accessible icon buttons.
Sets up production-ready shadcn-vue UI components in Vue/Nuxt apps with Tailwind CSS and Reka UI. Use for accessible forms, data tables, charts, dark mode, and component imports.
Provides Vue 3 + TypeScript project conventions: component boundaries, composables, Pinia state ownership, API/error handling, routing, and style isolation. Use when designing or reviewing Vue 3 project structure.