Title: Type error when add custom Iconify IconSet customCollections · Issue #360 · unplugin/unplugin-icons · GitHub
Open Graph Title: Type error when add custom Iconify IconSet customCollections · Issue #360 · unplugin/unplugin-icons
X Title: Type error when add custom Iconify IconSet customCollections · Issue #360 · unplugin/unplugin-icons
Description: Describe the bug I try to implement this example: But i got type error My code: import IconsResolver from 'unplugin-icons/resolver'; import type { Options } from 'unplugin-icons/types'; import { importDirectory, parseColors, runSVGO } fr...
Open Graph Description: Describe the bug I try to implement this example: But i got type error My code: import IconsResolver from 'unplugin-icons/resolver'; import type { Options } from 'unplugin-icons/types'; import { im...
X Description: Describe the bug I try to implement this example: But i got type error My code: import IconsResolver from 'unplugin-icons/resolver'; import type { Options } from 'unplugin-icons/types...
Opengraph URL: https://github.com/unplugin/unplugin-icons/issues/360
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type error when add custom Iconify IconSet customCollections","articleBody":"### Describe the bug\n\nI try to implement this [example:](https://github.com/iconify/tools/tree/main/%40iconify-demo/unplugin-svelte)\r\nBut i got type error\r\n\r\n\r\nMy code: \r\n```\r\nimport IconsResolver from 'unplugin-icons/resolver';\r\nimport type { Options } from 'unplugin-icons/types';\r\nimport { importDirectory, parseColors, runSVGO } from '@iconify/tools';\r\nimport { compareColors, stringToColor } from '@iconify/utils/lib/colors';\r\n\r\nconst assetsRootDir = 'src/assets/icons';\r\n\r\nexport const iconsResolver = IconsResolver(\r\n {\r\n prefix: 'i',\r\n customCollections: ['ppd'],\r\n },\r\n);\r\n\r\nexport const iconsConfig: Options = {\r\n compiler: 'vue2',\r\n customCollections: {\r\n ppd: async () => {\r\n // Load icons\r\n const iconSet = await importDirectory(\r\n `${assetsRootDir}/ppd`,\r\n {\r\n prefix: 'ppd',\r\n },\r\n );\r\n\r\n // Clean up each icon\r\n await iconSet.forEach((name) => {\r\n const svg = iconSet.toSVG(name);\r\n if (!svg)\r\n return;\r\n\r\n // Change color to `currentColor`\r\n const blackColor = stringToColor('black')!;\r\n\r\n parseColors(svg, {\r\n defaultColor: 'currentColor',\r\n callback: (attr, colorStr, color) => {\r\n // console.log('Color:', colorStr, color);\r\n\r\n // Change black to 'currentColor'\r\n if (color && compareColors(color, blackColor))\r\n return 'currentColor';\r\n\r\n switch (color?.type) {\r\n case 'none':\r\n case 'current':\r\n return color;\r\n }\r\n\r\n throw new Error(\r\n `Unexpected color \"${colorStr}\" in attribute ${attr}`,\r\n );\r\n },\r\n });\r\n\r\n // Optimise, but do not change shapes because they are animated\r\n runSVGO(svg, {\r\n keepShapes: true,\r\n });\r\n\r\n // Update icon in icon set\r\n iconSet.fromSVG(name, svg);\r\n });\r\n console.log(iconSet.export());\r\n\r\n // Export as IconifyJSON\r\n return iconSet.export();\r\n },\r\n },\r\n};\r\n```\r\n\r\npackage.json:\r\n```\r\n{\r\n \"name\": \"intro-storybook-vue-template\",\r\n \"version\": \"0.2.0\",\r\n \"private\": true,\r\n \"description\": \"Starter template to get up and running quickly with Vue and Storybook\",\r\n \"author\": \"Chromatic \u003chttps://chromatic.com/>\",\r\n \"license\": \"MIT\",\r\n \"repository\": {\r\n \"type\": \"git\",\r\n \"url\": \"https://github.com/chromaui/intro-storybook-vue-template\"\r\n },\r\n \"bugs\": {\r\n \"url\": \"https://github.com/chromaui/intro-storybook-vue-template/issues\"\r\n },\r\n \"scripts\": {\r\n \"dev\": \"vite\",\r\n \"build\": \"vite build\",\r\n \"preview\": \"vite preview\",\r\n \"lint\": \"eslint . --fix\",\r\n \"format\": \"prettier --write src/\",\r\n \"storybook\": \"storybook dev -p 6006\",\r\n \"build-storybook\": \"storybook build\",\r\n \"init-msw\": \"msw init public/\"\r\n },\r\n \"dependencies\": {\r\n \"@iconify/tools\": \"^4.0.4\",\r\n \"unplugin-icons\": \"^0.19.0\",\r\n \"vue\": \"^2.7.16\",\r\n \"vue-template-es2015-compiler\": \"^1.9.1\"\r\n },\r\n \"devDependencies\": {\r\n \"@antfu/eslint-config\": \"^2.16.2\",\r\n \"@storybook/addon-essentials\": \"^7.6.6\",\r\n \"@storybook/addon-interactions\": \"^7.6.6\",\r\n \"@storybook/addon-links\": \"^7.6.6\",\r\n \"@storybook/blocks\": \"^7.6.6\",\r\n \"@storybook/test\": \"^7.6.6\",\r\n \"@storybook/vue\": \"^7.6.6\",\r\n \"@storybook/vue-vite\": \"^7.6.6\",\r\n \"@types/node\": \"^20.12.12\",\r\n \"@vitejs/plugin-vue2\": \"^2.3.1\",\r\n \"eslint\": \"^8.50.0\",\r\n \"msw\": \"^1.2.1\",\r\n \"msw-storybook-addon\": \"^1.10.0\",\r\n \"react\": \"^18.2.0\",\r\n \"react-dom\": \"^18.2.0\",\r\n \"sass\": \"1.32\",\r\n \"storybook\": \"^7.6.6\",\r\n \"ts-node\": \"^10.9.2\",\r\n \"typescript\": \"^5.4.5\",\r\n \"unplugin-vue-components\": \"^0.26.0\",\r\n \"vite\": \"^4.1.4\",\r\n \"vue-cli-plugin-vuetify\": \"~2.5.1\",\r\n \"vue-component-type-helpers\": \"^2.0.16\",\r\n \"vue-template-compiler\": \"^2.7.16\",\r\n \"vuetify\": \"2.6.15\",\r\n \"vuetify-loader\": \"1.7.3\"\r\n },\r\n \"resolutions\": {\r\n \"jackspeak\": \"2.1.1\"\r\n }\r\n}\r\n```\r\n\n\n### Reproduction\n\nImplement this [example:](https://github.com/iconify/tools/tree/main/%40iconify-demo/unplugin-svelte)\n\n### System Info\n\n```Shell\nSystem:\r\n OS: Windows 11 10.0.22631\r\n CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz\r\n Memory: 2.17 GB / 15.89 GB\r\n Binaries:\r\n Node: 16.20.2 - C:\\Program Files\\nodejs\\node.EXE\r\n npm: 8.19.4 - C:\\Program Files\\nodejs\\npm.CMD\r\n Browsers:\r\n Edge: Chromium (123.0.2420.97)\r\n Internet Explorer: 11.0.22621.3527\n```\n\n\n### Used Package Manager\n\nnpm\n\n### Validations\n\n- [X] Follow our [Code of Conduct](https://github.com/antfu/.github/blob/main/CODE_OF_CONDUCT.md)\n- [X] Read the [Contributing Guide](https://github.com/antfu/contribute).\n- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.\n- [X] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.\n- [X] The provided reproduction is a [minimal reproducible](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.","author":{"url":"https://github.com/deicidem","@type":"Person","name":"deicidem"},"datePublished":"2024-05-14T13:15:58Z","url":"https://github.com/unplugin/unplugin-icons/issues/360"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f66d3182-93a3-eb8d-6dcc-44f8d44e8273 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E736:1BD385:24287A:32B99A:6B0058E3 |
| html-safe-nonce | 55a926caf797be30fba2fe0461803cf6e66e34342054fe9d0a52634841713605 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzM2OjFCRDM4NToyNDI4N0E6MzJCOTlBOjZCMDA1OEUzIiwidmlzaXRvcl9pZCI6IjM2MDcxOTY4NTg3ODg2MzI4MDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7ece1685ebb967cc130325bf931b69b8f36b1e08f24c0410f1766ce2db9912c7 |
| hovercard-subject-tag | issue:2295434274 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/unplugin/unplugin-icons/360/issue_layout |
| twitter:image | https://opengraph.githubassets.com/955cb2329c5466ff24115d692518f001554024b3fa5236eadd883862a7fc76bc/unplugin/unplugin-icons/issues/360 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/955cb2329c5466ff24115d692518f001554024b3fa5236eadd883862a7fc76bc/unplugin/unplugin-icons/issues/360 |
| og:image:alt | Describe the bug I try to implement this example: But i got type error My code: import IconsResolver from 'unplugin-icons/resolver'; import type { Options } from 'unplugin-icons/types'; import { im... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | deicidem |
| hostname | github.com |
| expected-hostname | github.com |
| None | 29be975efff6507a5d135de9c7d634cf7ff8f0c55222a64386ab3202209aaf73 |
| turbo-cache-control | no-preview |
| go-import | github.com/unplugin/unplugin-icons git https://github.com/unplugin/unplugin-icons.git |
| octolytics-dimension-user_id | 143585159 |
| octolytics-dimension-user_login | unplugin |
| octolytics-dimension-repository_id | 324073430 |
| octolytics-dimension-repository_nwo | unplugin/unplugin-icons |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 324073430 |
| octolytics-dimension-repository_network_root_nwo | unplugin/unplugin-icons |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | eacd927ba6112e3b01ba99c762bd699a4a4f5df7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width