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

vite-plugin-fontiny

v0.2.3

Published

A font file compression tool for Vite.

Downloads

88

Readme

vite-plugin-fontiny

npm version npm downloads bundle

简体中文 | English

Fontiny = Font + Tiny

Fontiny 是用于将字体文件中未被使用过的中文字符删除的工具。

目前只支持 ttf 格式的字体文件,未来会支持更多格式。

待办

  • [x] 生成一个 HTML 页面,展示哪些中文字符被保留,哪些被删除。
  • [ ] 用户可以自定义匹配字符的规则。
  • [ ] 支持更多类型的字体文件,如 otf、woff、woff2、eot。

安装

npm i -D vite-plugin-fontiny

使用方法

// vite.config.ts
import Fontiny from 'vite-plugin-fontiny'

export default {
  plugins: [
    Fontiny({
      // options
      fontFileNames: ['Example-Font-Regular.ttf']
    }),
  ],
}
@font-face {
  font-family: "Example Font";
  src: url("./assets/Example-Font-Regular.ttf") format("truetype")
}

Fontiny 不关心字体文件具体在什么路径,也不关心是在哪个 css 文件中使用了,只要这个字体在 css 中被使用了,并且在 fontFileNames 列表中,就会对它进行处理。

它会在你的代码中搜索中文字符,并从字体文件中删除未被使用的中文字符,达到减小字体文件的大小的目的。

ZCOOLKuaiLe-Regular.ttf [3,188 KB]

↓ ↓ ↓ ↓ ↓ ↓

在代码中搜索中文字符

[ "只", "有", "在", "代", "码", "中", "出", "现", "过", "的", "中", "文", "字", "符", "会", "在", "字", "体", "文", "件", "中", "保", "留", "在", "输", "入", "框", "中", "输", "入", "新", "文", "字", "查", "看", "效", "果" ]

↓ ↓ ↓ ↓ ↓ ↓

从字体文件中删除未使用的字符

↓ ↓ ↓ ↓ ↓ ↓

ZCOOLKuaiLe-Regular-Cx0eLuEs.ttf [24 KB]

实际压缩效果受代码中使用的中文字符数量影响

插件参数

fontFileNames

想要压缩的字体文件名称

type FontFileNames = string[]

required: true

include

代码扫描的范围

type Include = ReadonlyArray<string | RegExp> | string | RegExp | null | undefined

required: false 默认值: undefined

exclude

不进行代码扫描的范围

type Exclude = ReadonlyArray<string | RegExp> | string | RegExp | null | undefined

required: false 默认值: undefined

visualizer

如果设为 true,会在生成一个可视化页面展示压缩效果

运行 vite build 后,会在 .vite-fontiny 目录生成这个可视化页面,可以运行 npx serve .vite-inspect 命令来查看页面

type Visualizer = boolean

required: false 默认值: false

可视化页面示例图片

致谢

特别感谢 fonteditor-corefontmin@antfu