Skip to content

refactor(web): migrate icons to unplugin-icons - #1467

Merged
liruifengv merged 5 commits into
mainfrom
web-iconify
Jul 7, 2026
Merged

refactor(web): migrate icons to unplugin-icons#1467
liruifengv merged 5 commits into
mainfrom
web-iconify

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue. This addresses an internal simplification of apps/kimi-web's icon infrastructure.

Problem

apps/kimi-web maintained a hand-written icon-cropping script (scripts/gen-icon-data.mjs + scripts/gen-icon-catalog.mjs) that pre-extracted Remix Icon SVG bodies into src/lib/icon-data.ts, then used @iconify/utils' iconToSVG to render them at runtime. This added friction — every icon change required manually regenerating and committing a generated file — duplicated the name mapping across two scripts, and pulled @iconify/utils into the runtime bundle even though it was only needed at build time. @iconify/vue was also a declared dependency but never imported.

What changed

  • Switched the icon registry to unplugin-icons (Vite plugin, compiler: 'vue3'). Only icons statically imported in src/lib/icons.ts end up in the production bundle, fully offline and tree-shaken at build time.
  • Rewrote src/lib/icons.ts: each of 56 distinct Remix icons is imported as both a Vue component (~icons/ri/<name>) and a raw SVG string (~icons/ri/<name>?raw), backed by a Record<IconName, IconEntry> table for 59 internal names. The public API (<Icon name>, iconSvg(name, size), IconName, SIZE_PX, IconEntry) is unchanged, so the 127+ call sites need no edits.
  • Icon.vue now renders <component :is> with an unknown-name fallback, instead of v-html into a hand-written <svg>.
  • DesignSystemView §02 catalog is rendered via v-for over a new ICON_GROUPS export; the §02 copy no longer references the deleted scripts.
  • Deleted scripts/gen-icon-data.mjs, scripts/gen-icon-catalog.mjs, src/lib/icon-data.ts, the gen:icons npm script, and the NAME_TO_REMIX constant (dead code).
  • Removed @iconify/vue and @iconify/utils from dependencies; moved @iconify-json/ri to devDependencies (unplugin-icons needs it at build time). @iconify/utils survives only as a transitive dependency of mermaid and unplugin-icons.
  • Added an 11-line declare module '~icons/*?raw' ambient type shim in src/env.d.ts so ?raw imports type as string (unplugin-icons' Vue types declare ~icons/* as FunctionalComponent, which would otherwise conflict).
  • Updated scripts/check-style.mjs ICON_EXEMPT (removed Icon.vue since it no longer hand-writes an <svg>) and the .kw-icon comment in src/style.css.

All four quality gates pass: typecheck, vitest (339 tests), check:style, and build.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Replace the hand-written gen-icon-data.mjs + @iconify/utils runtime
rendering with unplugin-icons build-time imports. The public API
(<Icon name>, iconSvg, IconName, SIZE_PX, NAME_TO_REMIX) is unchanged;
127+ call sites are untouched.

- add unplugin-icons@^23.0.0 (devDep) + Vite Icons() plugin (compiler: vue3)
- rewrite src/lib/icons.ts: static ~icons/ri/* imports (component + ?raw)
  for 56 distinct Remix icons across 59 IconName entries
- Icon.vue renders <component :is> with unknown-name fallback
- append ICON_GROUPS export for DesignSystemView catalog
- DesignSystemView: v-for catalog, remove legacy-script references
- delete gen-icon-data.mjs, gen-icon-catalog.mjs, icon-data.ts,
  gen:icons script
- remove @iconify/vue and @iconify/utils from dependencies; move
  @iconify-json/ri to devDependencies
- drop Icon.vue from check-style ICON_EXEMPT (no hand-written <svg>)
NAME_TO_REMIX was a Record<IconName, string> table introduced to map
internal icon names to their ri: ids. After the unplugin-icons migration
it has no production consumers — only icons.test.ts imported it (for two
drift tests) and DesignSystemView mentioned it in descriptive copy. The
ICONS table already conveys the same ri: id via each entry's paired
component + ?raw imports (e.g. RiFolderOpenLine / RawFolderOpenLine).

- remove NAME_TO_REMIX const from src/lib/icons.ts (-63 lines)
- remove NAME_TO_REMIX import + describe block from icons.test.ts
- update DesignSystemView §02 copy: describe the import-pair idiom and
  stop claiming ICON_GROUPS is sourced from NAME_TO_REMIX
@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5f3ab12

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

❌ Nix build failed

Hash mismatch in pnpmDeps:

Hash
specified sha256-+hTrX3pa8fjK+eh4q2BqOEAm9C7zvMXrKf4bwbJoG98=
got sha256-RPjCWL7NqDSKgpHGL16zPlUOfjWN2rkaDY/4GFAD8VA=

Please update flake.nix with the got hash.

@pkg-pr-new

pkg-pr-new Bot commented Jul 7, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@5f3ab12
npx https://pkg.pr.new/@moonshot-ai/kimi-code@5f3ab12

commit: 5f3ab12

Adding unplugin-icons changed pnpm-lock.yaml, so the fixed-output
pnpmDeps derivation hash is stale. Update to the hash reported by the
Nix Build CI run.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b35fe65e43

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-web/package.json
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4ff2f8ef03

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-web/src/env.d.ts
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 4ff2f8ef03

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@liruifengv
liruifengv merged commit ee38545 into main Jul 7, 2026
10 checks passed
@liruifengv
liruifengv deleted the web-iconify branch July 7, 2026 08:44
@github-actions github-actions Bot mentioned this pull request Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant