{"id":20463712,"url":"https://github.com/iconfont-cli/taro-iconfont-cli","last_synced_at":"2025-04-04T11:08:58.536Z","repository":{"id":37706343,"uuid":"210790608","full_name":"iconfont-cli/taro-iconfont-cli","owner":"iconfont-cli","description":"在Taro框架中使用iconfont图标，支持多端，支持多色彩，不依赖字体。","archived":false,"fork":false,"pushed_at":"2023-07-31T03:08:05.000Z","size":776,"stargazers_count":363,"open_issues_count":46,"forks_count":49,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T10:02:14.878Z","etag":null,"topics":["iconfont","iconfont-cli","mini-program-iconfont","react-native-iconnfont","taro","taro-iconfont"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/iconfont-cli.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2019-09-25T08:10:13.000Z","updated_at":"2025-03-23T13:38:40.000Z","dependencies_parsed_at":"2024-06-18T21:15:58.926Z","dependency_job_id":"9cf19006-0373-4ef4-ba50-c36af9c041db","html_url":"https://github.com/iconfont-cli/taro-iconfont-cli","commit_stats":{"total_commits":94,"total_committers":5,"mean_commits":18.8,"dds":0.06382978723404253,"last_synced_commit":"ba7b0c68bd7ab9b24c58bf10dba9860f2ed95c23"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iconfont-cli%2Ftaro-iconfont-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iconfont-cli%2Ftaro-iconfont-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iconfont-cli%2Ftaro-iconfont-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iconfont-cli%2Ftaro-iconfont-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iconfont-cli","download_url":"https://codeload.github.com/iconfont-cli/taro-iconfont-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166167,"owners_count":20894654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["iconfont","iconfont-cli","mini-program-iconfont","react-native-iconnfont","taro","taro-iconfont"],"created_at":"2024-11-15T13:12:49.230Z","updated_at":"2025-04-04T11:08:58.516Z","avatar_url":"https://github.com/iconfont-cli.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# taro-iconfont-cli\n在Taro框架中使用iconfont图标，不依赖字体，支持多色彩。\n\n# 支持平台\n\n* 微信小程序\n* 支付宝小程序\n* 百度小程序\n* 头条小程序\n* QQ小程序\n* H5\n\n# 特性\n1、一键生成标准组件，多端支持\n\u003cbr\u003e\n2、使用方便，import即可\n\u003cbr\u003e\n3、支持多色彩\n\u003cbr\u003e\n4、支持自定义颜色\n\u003cbr\u003e\n5、支持es6和typescript两种模式\n\n# Step 1\n安装插件\n\n**如果您使用Taro2.x，请安装 `taro-iconfont-cli@2.1.0`，并阅读旧版的[README.md](https://github.com/iconfont-cli/taro-iconfont-cli/blob/v2.1.0/README.md)**\n\n```bash\n# Yarn\nyarn add taro-iconfont-cli --dev\n\n# Npm\nnpm install taro-iconfont-cli --save-dev\n```\n\n\n# Step 2\n生成配置文件\n```bash\nnpx iconfont-init\n\n# 可传入配置输出路径\n# npx iconfont-init --output iconfont.json\n```\n此时项目根目录会生成一个`iconfont.json`的文件，内容如下：\n```json\n{\n  \"symbol_url\": \"请参考README.md，复制 http://iconfont.cn 官网提供的JS链接\",\n  \"save_dir\": \"./src/components/iconfont\",\n  \"use_typescript\": false,\n  \"platforms\": \"*\",\n  \"use_rpx\": true,\n  \"trim_icon_prefix\": \"icon\",\n  \"default_icon_size\": 18,\n  \"design_width\": 750\n}\n```\n### 配置参数说明：\n### symbol_url\n请直接复制[iconfont](http://iconfont.cn)官网提供的项目链接。请务必看清是`.js`后缀而不是.css后缀。如果你现在还没有创建iconfont的仓库，那么可以填入这个链接去测试：`http://at.alicdn.com/t/font_1373348_kk9y3jk2omq.js`\n\n\u003cbr /\u003e\n\n![](https://github.com/fwh1990/mini-program-iconfont-cli/blob/master/images/symbol-url.png?raw=true)\n\n### save_dir\n根据iconfont图标生成的组件存放的位置。每次生成组件之前，该文件夹都会被清空。\n\n### use_typescript\n如果您的项目使用Typescript编写，请设置为true。这个选项将决定生成的图标组件是`.tsx`还是`.js`后缀。\n\n当该值为false时，我们会为您的图标生成`.js`和`.d.ts`两个文件，以便您能享受到最好的开发体验。\n\n### platforms\n选择需要支持的平台，默认是`*`，意味着所有平台都需要支持（如果有）。如果你只想支持部分平台，也可以设置成数组：\n```json5\n{\n  // 选择你需要的平台\n  // 说明 =\u003e  weapp: 微信  |  swan: 百度  |  alipay: 支付宝  |  tt: 字节跳动\n  \"platforms\": [\"weapp\", \"swan\", \"alipay\", \"h5\", \"tt\", \"qq\"]\n}\n```\n\n### use_rpx\n是否使用[尺寸单位rpx](https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxss.html#%E5%B0%BA%E5%AF%B8%E5%8D%95%E4%BD%8D)还是普通的像素单位`px`。默认值为true，与Taro保持一致的缩放。您也可以设置为false，强制使用`px`\n\n### design_width\n若 `use_rpx: true` 且当前设计图尺寸不为 750 时，可以通过修改这个字段来修改设计尺寸。\n\n### trim_icon_prefix\n如果你的图标有通用的前缀，而你在使用的时候又不想重复去写，那么可以通过这种配置这个选项把前缀统一去掉。\n\n### default_icon_size\n我们将为每个生成的图标组件加入默认的字体大小，当然，你也可以通过传入props的方式改变这个size值。\n\n\n# Step 3\n开始生成Taro标准组件\n```bash\nnpx iconfont-taro\n\n# 可传入配置文件路径\n# npx iconfont-taro --config iconfont.json\n```\n生成后查看您设置的保存目录中是否含有所有的图标\n\n-------\n\n在生成代码之前，你可以顺便参考[snapshots目录](https://github.com/iconfont-cli/taro-iconfont-cli/tree/master/snapshots)自动生成的快照文件。\n\n# Step 4\n由于Taro3.0的架构变更，您需要在`src/app.config.js`下填写一次`usingComponents`。\n```typescript\n// src/app.config.js\nimport { useGlobalIconFont } from './components/iconfont/helper';\n\nexport default {\n  usingComponents: Object.assign(useGlobalIconFont()),\n}\n```\n\n这并不是一个多好的方案，毕竟还需要开发者关注这个细节。也许能用webpack的plugin解决或者等官方推出更好的方案，有任何更好的idea欢迎提供。\n\n# 使用\n在Page中使用图标\n```jsx harmony\nimport React, { Component } from 'react';\nimport IconFont from '../components/iconfont';\n\nclass App extends Component {\n  render() {\n    return \u003cIconFont name=\"alipay\" /\u003e;\n  }\n}\n\nexport default App;\n```\n更多用法：\n```jsx harmony\n// 原色彩\n\u003cIconFont name=\"alipay\" /\u003e\n\n// 单色：红色\n\u003cIconFont name=\"alipay\" color=\"red\" /\u003e\n\n// 多色：红色+橘色\n\u003cIconFont name=\"alipay\" color={['red', 'orange']} size={300} /\u003e\n\n// 不同格式的颜色写法\n\u003cIconFont name=\"alipay\" color={['#333', 'rgb(50, 124, 39)']} /\u003e\n\n\n// 与文字对齐\n\u003cView style={{ display: 'flex', alignItems: 'center' }}\u003e\n  \u003cText\u003eHello\u003c/text\u003e\n  \u003cIconFont name=\"alipay\" /\u003e\n\u003c/View\u003e\n```\n\n# 更新图标\n当您在iconfont.cn中的图标有变更时，只需更改配置`symbol_url`，然后再次执行`Step 3`即可生成最新的图标组件\n```bash\n# 修改 symbol_url 配置后执行：\nnpx iconfont-taro\n```\n\n--------\n\n欢迎使用，并给我一些反馈和建议，让这个库做的更好\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficonfont-cli%2Ftaro-iconfont-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficonfont-cli%2Ftaro-iconfont-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficonfont-cli%2Ftaro-iconfont-cli/lists"}