{"id":31970671,"url":"https://github.com/winjs-dev/winjs-plugin-icons-legacy","last_synced_at":"2026-07-15T23:32:36.294Z","repository":{"id":312224352,"uuid":"1046731054","full_name":"winjs-dev/winjs-plugin-icons-legacy","owner":"winjs-dev","description":"A WinJS plugin for legacy SVG icons solution, specifically designed for Vue2 projects using svg-sprite-loader sprite technology.","archived":false,"fork":false,"pushed_at":"2025-08-29T06:52:57.000Z","size":357,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-22T01:29:32.118Z","etag":null,"topics":["plugins","svg-icons","svg-sprite-loader","winjs"],"latest_commit_sha":null,"homepage":"https://winjs-dev.github.io/winjs-docs/plugins/iconslegacy","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/winjs-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-29T06:15:18.000Z","updated_at":"2025-08-29T06:54:03.000Z","dependencies_parsed_at":"2025-08-29T10:41:50.358Z","dependency_job_id":"7d8a3ce1-eb66-405b-81ce-60777ecbdfed","html_url":"https://github.com/winjs-dev/winjs-plugin-icons-legacy","commit_stats":null,"previous_names":["winjs-dev/winjs-plugin-icons-legacy"],"tags_count":0,"template":false,"template_full_name":"winjs-dev/winjs-plugin-template","purl":"pkg:github/winjs-dev/winjs-plugin-icons-legacy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winjs-dev%2Fwinjs-plugin-icons-legacy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winjs-dev%2Fwinjs-plugin-icons-legacy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winjs-dev%2Fwinjs-plugin-icons-legacy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winjs-dev%2Fwinjs-plugin-icons-legacy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/winjs-dev","download_url":"https://codeload.github.com/winjs-dev/winjs-plugin-icons-legacy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/winjs-dev%2Fwinjs-plugin-icons-legacy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35524897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-15T02:00:06.706Z","response_time":131,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["plugins","svg-icons","svg-sprite-loader","winjs"],"created_at":"2025-10-14T19:18:07.580Z","updated_at":"2026-07-15T23:32:36.277Z","avatar_url":"https://github.com/winjs-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# winjs-plugin-icons-legacy\n\n适配 WinJS 的 SVG 图标遗留方案插件，专为 Vue2 项目设计，使用 svg-sprite-loader 雪碧图技术。\n\n\u003cp\u003e\n  \u003ca href=\"https://npmjs.com/package/@winner-fed/plugin-icons-legacy\"\u003e\n   \u003cimg src=\"https://img.shields.io/npm/v/@winner-fed/plugin-icons-legacy?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"npm version\" /\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"license\" /\u003e\n  \u003ca href=\"https://npmcharts.com/compare/@winner-fed/plugin-icons-legacy?minimal=true\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@winner-fed/plugin-icons-legacy.svg?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"downloads\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## 功能特性\n\n- ✅ **SVG 雪碧图方案**：使用 svg-sprite-loader 将 SVG 图标转换为 symbol 标签\n- ✅ **自动优化**：集成 svgo-loader 自动优化 SVG 文件，移除填充和描边属性\n- ✅ **Vue2 专用**：专门为 Vue2 项目优化，配合 @winner-fed/preset-vue2 使用\n- ✅ **自定义路径**：支持配置多个图标目录路径\n- ✅ **开箱即用**：默认处理 `src/icons` 目录下的 SVG 文件\n- ✅ **Webpack 兼容**：同时支持 Webpack 和 Rsbuild 构建方式\n\n## 安装\n\n```bash\nnpm install @winner-fed/plugin-icons-legacy -D\n# 或\nyarn add @winner-fed/plugin-icons-legacy -D\n# 或\npnpm add @winner-fed/plugin-icons-legacy -D\n```\n\n## 配置\n\n### 基本配置\n\n在 `.winrc.ts` 文件中配置：\n\n```typescript\nimport { defineConfig } from 'win';\n\nexport default defineConfig({\n  presets: [require.resolve('@winner-fed/preset-vue2')],\n  plugins: [require.resolve('@winner-fed/plugin-icons-legacy')],\n  iconsLegacy: {\n    // 可选：自定义图标目录\n    include: [\n      'src/assets/icons',\n      'src/components/icons'\n    ]\n  }\n});\n```\n\n### 配置选项\n\n| 选项 | 类型 | 默认值 | 描述 |\n| --- | --- | --- | --- |\n| `include` | `string[]` | `[]` | 额外的图标目录路径，默认已包含 `src/icons` |\n\n## 使用方式\n\n### 1. 目录结构\n\n```\nsrc/\n├── icons/\n│   ├── index.js          # 图标入口文件\n│   └── svg/\n│       ├── dog.svg       # 图标文件\n│       ├── cat.svg\n│       └── ...\n├── components/\n│   └── SvgIcon/\n│       └── index.vue     # 图标组件\n└── pages/\n    └── index.vue\n```\n\n### 2. 图标入口文件\n\n创建 `src/icons/index.js`：\n\n```javascript\nconst req = require.context('./svg', false, /\\.svg$/);\nconst requireAll = (requireContext) =\u003e requireContext.keys();\n\n// 自动引入所有 SVG 图标\nrequireAll(req).map(req);\n\nconst re = /\\.\\/(.*)\\.svg/;\n\n// 导出图标名称列表（可选）\nexport const iconNames = requireAll(req).map((i) =\u003e {\n  return i.match(re)[1];\n});\n```\n\n### 3. SvgIcon 组件\n\n创建 `src/components/SvgIcon/index.vue`：\n\n```vue\n\u003ctemplate\u003e\n  \u003csvg :class=\"['svg-icon', className]\" aria-hidden=\"true\" @click=\"clickHandle\"\u003e\n    \u003cuse :xlink:href=\"'#icon-' + (iconName || name)\" /\u003e\n  \u003c/svg\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\nexport default {\n  name: 'SvgIcon',\n  props: {\n    iconName: {\n      type: String,\n      required: false\n    },\n    name: {\n      type: String,\n      required: false\n    },\n    className: {\n      type: [String, Array],\n      default: ''\n    }\n  },\n  mounted() {\n    if (!this.name \u0026\u0026 !this.iconName) {\n      console.error('Missing required prop: \"iconName or name\"');\n    }\n  },\n  methods: {\n    clickHandle() {\n      this.$emit('click');\n    }\n  }\n};\n\u003c/script\u003e\n\n\u003cstyle scoped\u003e\n.svg-icon {\n  width: 1em;\n  height: 1em;\n  fill: currentColor;\n  vertical-align: -0.15em;\n  overflow: visible;\n  position: relative;\n}\n\u003c/style\u003e\n```\n\n### 4. 在页面中使用\n\n```vue\n\u003ctemplate\u003e\n  \u003cdiv\u003e\n    \u003c!-- 使用 name 属性 --\u003e\n    \u003csvg-icon name=\"dog\" class=\"icon-large\"\u003e\u003c/svg-icon\u003e\n    \n    \u003c!-- 使用 iconName 属性 --\u003e\n    \u003csvg-icon iconName=\"cat\" @click=\"handleIconClick\"\u003e\u003c/svg-icon\u003e\n    \n    \u003c!-- 自定义样式 --\u003e\n    \u003csvg-icon name=\"star\" :className=\"['icon-star', 'active']\"\u003e\u003c/svg-icon\u003e\n  \u003c/div\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\n// 引入图标\nimport '@/icons';\n\nexport default {\n  methods: {\n    handleIconClick() {\n      console.log('图标被点击了');\n    }\n  }\n};\n\u003c/script\u003e\n\n\u003cstyle\u003e\n.icon-large {\n  font-size: 24px;\n  color: #1890ff;\n}\n\n.icon-star.active {\n  color: #faad14;\n}\n\u003c/style\u003e\n```\n\n### 5. 全局注册组件\n\n在 `main.js` 中全局注册：\n\n```javascript\nimport Vue from 'vue';\nimport SvgIcon from '@/components/SvgIcon';\n\n// 引入图标\nimport '@/icons';\n\n// 全局注册组件\nVue.component('svg-icon', SvgIcon);\n\n// 或者使用插件方式\nconst iconPlugin = {\n  install(Vue) {\n    Vue.component('svg-icon', SvgIcon);\n  }\n};\n\nVue.use(iconPlugin);\n```\n\n## 高级用法\n\n### 动态引入图标\n\n```javascript\n// 动态引入特定图标\nconst importIcon = (name) =\u003e {\n  return import(`@/icons/svg/${name}.svg`);\n};\n\n// 批量引入\nconst importIcons = (names) =\u003e {\n  return Promise.all(names.map(name =\u003e importIcon(name)));\n};\n```\n\n### 图标列表获取\n\n```javascript\n// 获取所有可用图标名称\nimport { iconNames } from '@/icons';\n\nexport default {\n  data() {\n    return {\n      availableIcons: iconNames\n    };\n  }\n};\n```\n\n## 技术原理\n\n1. **svg-sprite-loader**：将 SVG 文件转换为 `\u003csymbol\u003e` 标签，并生成雪碧图\n2. **svgo-loader**：优化 SVG 文件，移除不必要的属性（如 fill、stroke）\n3. **符号引用**：通过 `\u003cuse\u003e` 标签引用 symbol，实现图标复用\n4. **自动配置**：插件自动配置 Webpack 和 Rsbuild 的加载规则\n\n## 注意事项\n\n- 仅支持 Vue2 项目，需要配合 `@winner-fed/preset-vue2` 使用\n- SVG 文件应放在指定的图标目录中（默认 `src/icons`）\n- 图标名称基于文件名，使用时需要保持一致\n- 建议 SVG 文件不要包含 fill 和 stroke 属性，让组件控制颜色\n\n## 常见问题\n\n### Q: 为什么图标不显示？\nA: 请确保：\n1. 正确引入了 `@/icons` 入口文件\n2. SVG 文件放在正确的目录中\n3. 图标名称与文件名一致\n4. 配置了正确的 preset-vue2\n\n### Q: 如何自定义图标样式？\nA: 通过 CSS 控制：\n```css\n.svg-icon {\n  width: 20px;\n  height: 20px;\n  fill: #333;\n}\n```\n\n### Q: 如何添加更多图标目录？\nA: 在配置中添加 `include` 选项：\n```typescript\niconsLegacy: {\n  include: ['src/assets/icons', 'src/shared/icons']\n}\n```\n\n## 许可证\n\n[MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinjs-dev%2Fwinjs-plugin-icons-legacy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwinjs-dev%2Fwinjs-plugin-icons-legacy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwinjs-dev%2Fwinjs-plugin-icons-legacy/lists"}