Icon Font Skill
Use this skill to generate a local iconfont.js from project SVG icons while preserving Ant Design usage:
import { createFromIconfontCN } from '@ant-design/icons';
const IconFont = createFromIconfontCN({
scriptUrl: '/iconfont-js/iconfont.js',
});
export default IconFont;
Workflow
- Locate the frontend project root and SVG icon directory.
- Generate the local iconfont runtime:
npx iconfont-js-cli generate --input <svg-dir> --visualize
- If the project uses a different public directory, pass it explicitly:
npx iconfont-js-cli generate --input <svg-dir> --output <project-public-dir>/iconfont-js --visualize
- Update
createFromIconfontCN({ scriptUrl })to the generated public path, usually:
scriptUrl: '/iconfont-js/iconfont.js'
- Open or report the generated preview:
public/iconfont-js/preview.html
CLI Rules
--inputis required.- Default output is
public/iconfont-js/iconfont.js. - Icon types are generated from filenames:
add-user.svg->icon-add-useruser_profile.svg->icon-user-profile
- SVG files over
50 KiBare included with warnings. - SVG files over
100 KiBare skipped by default. - Raise the hard limit only when the project intentionally uses complex SVG icons:
npx iconfont-js-cli generate --input <svg-dir> --max-size-kb 200 --visualize
- Duplicate generated icon types are fatal. Rename source SVG files before regenerating.
- Use a custom prefix when the project expects a different
typenamespace:
npx iconfont-js-cli generate --input <svg-dir> --prefix app --visualize
Visualization
Generate a preview from an existing generated script:
npx iconfont-js-cli visualize --input public/iconfont-js/iconfont.js
The preview is a standalone preview.html that works from file:// and shows type, source filename, size, and warning state for each icon.
Verification
After generation:
- Check CLI output for skipped files and warnings.
- Inspect
preview.htmland search for expected icon types. - Confirm the frontend imports the generated script from the public path.
- Use
<IconFont type="icon-example" />with a known generated type in the app.
Do not reimplement SVG scanning or sprite generation inline. Use iconfont-js-cli as the source of truth.