npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

iconfont-to-tsx

v1.0.5

Published

把 iconfont 图标批量转换成多 tsx react 组件。不依赖字体,支持多色彩。

Downloads

22

Readme

iconfont2Tsx

把 iconfont 图标批量转换成多 tsx react 组件。不依赖字体,支持多色彩。

特性

1、纯组件 2、不依赖字体文件 3、支持 px 和 rpx 两种格式 4、原样渲染多色彩图标 5、图标颜色可定制

Step 1

安装插件

# Yarn
yarn add iconfont-to-tsx --dev

# Npm
npm install iconfont-to-tsx --save-dev

Step 2

生成配置文件

npx iconfont2Tsx-init

# 可传入配置文件输出路径
# npx iconfont2Tsx-init --output iconfont.json

此时项目根目录会生成一个iconfont.json的文件,内容如下:

{
  "symbol_url": "请参考README.md,复制 http://iconfont.cn 官网提供的JS链接",
  "save_dir": "./src/Iconfont",
  "icon_all_name": "Iconfont",
  "is_signle": true,
  "use_rpx": false,
  "trim_icon_prefix": "",
  "default_icon_size": 16,
  "design_width": 750
}

配置参数说明:

symbol_url

请直接复制iconfont官网提供的项目链接。请务必看清是.js后缀而不是.css后缀,可使用 //at.alicdn.com/t/c/font_4492100_gbyyt9o35yg.js 试一下

save_dir

根据 iconfont 图标生成的组件存放的位置。每次生成组件之前,该文件夹都会被清空。

icon_all_name

指定全量图标的组件名

is_signle

控制是否生成单个图标组件

use_rpx

使用微信提供的尺寸单位 rpx还是普通的像素单位px。默认值为 false,即使用px

trim_icon_prefix

如果你的图标有通用的前缀,而你在使用的时候又不想重复去写,那么可以通过配置这个选项把前缀统一去掉。

default_icon_size

我们将为每个生成的图标组件加入默认的字体大小,当然,你也可以通过传入 props 的方式改变这个 size 值。

design_width

默认为 750px,你可以通过配置这个选项来改变这个值。

Step 3

生成组件

# 可传入配置文件路径
# npx iconfont2Tsx-generate --config iconfont.json

npx iconfont2Tsx-generate

生成后查看您设置的保存目录中是否含有所有的图标

使用

在 page 中使用图标。

// 原色彩
<Iconfont name="alipay" />

// 单色:红色
<Iconfont name="alipay" color="red" />

// 多色:红色+橘色
<Iconfont name="alipay" color={["red", "orange"]} size="300" />

// 不同格式的颜色写法
// 暂不支持 rgba 写法,因为需要encodeURIComponent转码
<Iconfont name="alipay" color={["#333", "red"]} />

更新图标

当您在 iconfont.cn 中的图标有变更时,只需更改配置symbol_url,然后再次执行Step 3即可生成最新的图标组件。欢迎使用,并给我一些反馈和建议.