Gathering detailed insights and metrics for react-native-iconfont-cli
Gathering detailed insights and metrics for react-native-iconfont-cli
Gathering detailed insights and metrics for react-native-iconfont-cli
Gathering detailed insights and metrics for react-native-iconfont-cli
react-native-iconpark-cli
基于[react-native-iconfont-cli](https://github.com/iconfont-cli/react-native-iconfont-cli)改造,用于适配iconpark
react-native-iconfont-cli-mod-by-jasonfeng
这是 fork 版本:
hi-react-native-iconfont-cli
用纯JS把iconfont.cn的图标转换成RN组件,不依赖字体,支持多色彩,支持热更新
@grewer/react-native-iconfont-cli
fork react-native-iconfont-cli 并且添加了 本地 svg 的支持
npm install react-native-iconfont-cli
Typescript
Module System
Node Version
NPM Version
TypeScript (62.55%)
JavaScript (35.55%)
Shell (1.9%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
470 Stars
123 Commits
64 Forks
6 Watchers
8 Branches
5 Contributors
Updated on Jul 12, 2025
Latest Version
2.2.4
Package Id
react-native-iconfont-cli@2.2.4
Unpacked Size
32.62 kB
Size
9.85 kB
File Count
35
NPM Version
6.14.12
Node Version
14.16.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
用纯JS把iconfont.cn的图标转换成RN组件,不依赖字体,支持多色彩,支持热更新
通常地,当我们想在RN里使用iconfont,我们可能会借助react-native-vector-icons
导入ttf字体文件,或者直接手动下载各个svg文件到本地,然后单个使用。
使用ttf字体有一个弊端,就是每次更新图标,都要相应的更新ttf文件,然后再次打包发布APP。而且ttf不支持多种色彩的图标,导致所有图标都是单色。如果你是借助react-native-vector-icons
,该库内置了10多套ttf文件,合起来有2M
左右;你可能用不到它们,但是它们仍然会被打包进你的APP里。
下载svg到本地也不方便,因为你需要额外维护一份图标字体,有可能造成线上和本地的图标不一致问题。而且如果你想动态地改变svg的渲染色彩,基本上是不可能的,只能渲染原图的颜色。
为了解决这些问题,我用纯Javascript实现iconfont到React组件的转换操作,不需要依赖ttf字体文件,不需要手动下载图标到本地。
1、纯组件,不依赖字体,体积小
2、支持渲染多色彩图标,支持自定义颜色
3、支持热更新
4、自动化生成图标组件,支持es6和typescript两种文件格式
安装插件
1# Yarn 2yarn add react-native-svg 3yarn add react-native-iconfont-cli --dev 4 5# Npm 6npm install react-native-svg 7npm install react-native-iconfont-cli --save-dev
静态链接。请注意您使用的React-Native版本号
1# RN < 0.60 2react-native link react-native-svg 3 4# RN >= 0.60 5cd ios && pod install
生成配置文件
1npx iconfont-init
此时项目根目录会生成一个iconfont.json
的文件,内容如下:
1{ 2 "symbol_url": "请参考README.md,复制官网提供的JS链接", 3 "use_typescript": false, 4 "save_dir": "./src/iconfont", 5 "trim_icon_prefix": "icon", 6 "default_icon_size": 18, 7 "local_svgs": "./localSvgs" 8}
请直接复制iconfont官网提供的项目链接。请务必看清是.js
后缀而不是.css后缀。如果你现在还没有创建iconfont的仓库,那么可以填入这个链接去测试:http://at.alicdn.com/t/font_1373348_ghk94ooopqr.js
如果您的项目使用Typescript编写,请设置为true。这个选项将决定生成的图标组件是.tsx
还是.js
后缀。
当该值为false时,我们会为您的图标生成.js
和.d.ts
两种文件,以便您能享受到最好的开发体验。
根据iconfont图标生成的组件存放的位置。每次生成组件之前,该文件夹都会被清空。
如果你的图标有通用的前缀,而你在使用的时候又不想重复去写,那么可以通过这种配置这个选项把前缀统一去掉。
我们将为每个生成的图标组件加入默认的字体大小,当然,你也可以通过传入props的方式改变这个size值。
本地 svg 的路径, 配置此项后在路径中添加 svg 文件即可。支持渐变图标(iconfont官网不能上传渐变图标)。
注 1: 暂不支持 color
参数
注 2: 如果启用该功能,请确保react-native-svg
的版本>=9.13.0
开始生成React-Native标准组件
1npx iconfont-rn
生成后查看您设置的保存目录中是否含有所有的图标,你可以参考snapshots目录的快照文件,以区分不同模式下的图标结构。
1、使用汇总Icon
组件:
1import IconFont from '../src/iconfont'; 2 3export const App = () => { 4 return ( 5 <View> 6 <IconFont name="alipay" size={20} /> 7 <IconFont name="wechat" /> 8 </View> 9 ); 10};
2、使用单个图标。这样可以避免没用到的图标也打包进App:
1import IconAlipay from '../src/iconfont/IconAlipay'; 2import IconWechat from '../src/iconfont/IconWechat'; 3 4export const App = () => { 5 return ( 6 <View> 7 <IconAlipay size={20} /> 8 <IconWechat /> 9 </View> 10 ); 11};
根据配置default_icon_size
,每个图标都会有一个默认的尺寸,你可以随时覆盖。
1<IconFont name="alipay" size={20} />
单色图标,如果不指定颜色值,图标将渲染原本的颜色。如果你想设置为其他的颜色,那么设置一个你想要的颜色即可。
注意:如果你在props传入的color是字符串而不是数组,那么即使原本是多色彩的图标,也会变成单色图标。
1<IconFont name="alipay" color="green" />
多色彩的图标,如果不指定颜色值,图标将渲染原本的多色彩。如果你想设置为其他的颜色,那么设置一组你想要的颜色即可
1<IconFont name="alipay" color={['green', 'orange']} />
颜色组的数量以及排序,需要根据当前图标的信息来确定。您需要进入图标组件中查看并得出结论。
当您在iconfont.cn中的图标有变更时,只需更改配置symbol_url
,然后再次执行Step 4
即可生成最新的图标组件
1# 修改 symbol_url 配置后执行: 2npx iconfont-rn
欢迎使用,并给我一些反馈和建议,让这个库做的更好
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/19 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
66 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More