{"id":28397512,"url":"https://github.com/hopgoldy/google-font-splitter","last_synced_at":"2025-06-28T08:31:46.297Z","repository":{"id":57710640,"uuid":"512081530","full_name":"HoPGoldy/google-font-splitter","owner":"HoPGoldy","description":"A simple CLI to download google font with splits","archived":false,"fork":false,"pushed_at":"2022-07-10T07:20:26.000Z","size":183,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-01T11:06:59.939Z","etag":null,"topics":["cli","font","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/HoPGoldy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-09T03:14:44.000Z","updated_at":"2025-01-21T08:29:27.000Z","dependencies_parsed_at":"2022-09-11T02:23:04.429Z","dependency_job_id":null,"html_url":"https://github.com/HoPGoldy/google-font-splitter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/HoPGoldy/google-font-splitter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HoPGoldy%2Fgoogle-font-splitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HoPGoldy%2Fgoogle-font-splitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HoPGoldy%2Fgoogle-font-splitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HoPGoldy%2Fgoogle-font-splitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HoPGoldy","download_url":"https://codeload.github.com/HoPGoldy/google-font-splitter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HoPGoldy%2Fgoogle-font-splitter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262400549,"owners_count":23305309,"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":["cli","font","typescript"],"created_at":"2025-06-01T01:36:58.586Z","updated_at":"2025-06-28T08:31:46.285Z","avatar_url":"https://github.com/HoPGoldy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# google-font-splitter\n\n![](https://img.shields.io/npm/v/google-font-splitter)\n![](https://img.shields.io/github/languages/code-size/hopgoldy/google-font-splitter)\n\n将 google-font 提供的在线字体文件下载至本地的工具。\n\ngoogle-font 提供的在线字体使用了 `unicode-range` 进行了字体包分割，可以有效的提升字体的加载速度。\n\n但由于网络、环境等问题影响，某些项目不能正常的引用 google 字体，所以这个工具会将指定的谷歌在线下载至本地，以便于项目直接本地引用。\n\n## 安装\n\n需求：`node 12+`\n\n```shell\nnpm install -g google-font-splitter\n```\n\n## 如何使用\n\n本工具的使用分为两步，获取在线字体链接、下载字体文件。\n\n**第一步：获取在线字体链接**\n\n打开 [google fonts](https://fonts.google.com/)，搜索选择要下载的字体。\n\n在字体详情页向下滚动找到 Styles，并在点击要使用的字体右侧的 **Select this style** 按钮。\n\n[![jsa2Ox.png](https://s1.ax1x.com/2022/07/10/jsa2Ox.png)](https://imgtu.com/i/jsa2Ox)\n\n在右侧的 **Selected family** 面板下方找到找到在线字体链接并将其复制出来（只需要链接即可，**不需要** 复制整行 link 标签）：\n\n[![jsag61.png](https://s1.ax1x.com/2022/07/10/jsag61.png)](https://imgtu.com/i/jsag61)\n\n**第二步：下载字体文件**\n\n找一个空文件夹，并执行如下命令：\n\n```bash\ngoogle-font-splitter \"https://你复制出的在线字体链接\"\n# 例如 google-font-splitter \"https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@100;300;400\u0026display=swap\"\n```\n\n回车后工具将会打印如下输出：\n\n```\ndownloading entry css file...\nrecast entry file and generating font download tasks...\nsave entry css file...\ndownloading font source ======================================== 100% 291/291\ndownload complate, save to D:\\project\\google-font-splitter\\font-result\\noto-sans-sc\n```\n\n然后你就可以在日志最后一行的文件夹中找到下载好的字体文件夹了，目录如下：\n\n```\nnoto-sans-sc\n├── s/notosanssc/xxx/...\n└── noto-sans-sc.css\n```\n\n包含一个存放分割好的字体文件的文件夹和一个与目录同名的 css 文件，这个 css 文件即为入口文件。**只需要将该文件夹复制到你的项目中并使用 \\\u003clink /\u003e 标签引用进来即可。**\n\n## 命令行参数及配置项\n\n你可以随时使用 `--help` 参数查看帮助信息。\n\n- **参数 `url`**\n\n    工具只接受一个参数，即 google fonts 的在线字体链接，请确保该链接指向的是一个 css 文件。\n\n- **配置项 `-r, --root \u003cpath\u003e`**\n\n    字体入口 css 文件引入字体源文件的路径前缀，默认为同级相对路径（*所以默认时需要把入口 css 和字体源文件放在同级目录下*）。\n    \n    你可以通过该参数指定字体源文件的存放位置。例如将字体存放至独立的 cdn 网络：\n\n    ```\n    google-font-splitter \"https://fonts.googleapis.com/...\" -r https://your-custom-cdn/public/fonts/\n    ```\n\n- **配置项 `-d, --dist \u003csavePath\u003e`**\n\n    字体文件要下载到的位置，默认为 `./font-result`。\n\n- **配置项 `-n, --name \u003cfileName\u003e`**\n\n    字体入口文件的名称，即下载目录中的文件夹名称和其中的入口 css 文件名。\n    \n    默认会从提供的 google fonts 链接中解析，当解析失败时会使用当前的毫秒时间戳。\n\n- **配置项 ` -c, --concurrent \u003cnumber\u003e`**\n\n    下载分割的字体源文件时的并发数量，默认为 30。\n\n## 在项目中引用\n\n使用方式非常简单，只需要使用 `\u003clink href=\"xxx.css\" rel=\"stylesheet\"\u003e` 将下载好的字体入口文件引入进来即可。\n\n下面是一些常见框架的引用方式（假定下载好的字体文件存放在 noto-sans-sc 文件夹中，且入口文件为 `noto-sans-sc/noto-sans-sc.css`）：\n\n**vue2（vue-cli）**\n\n将下载好的字体文件夹复制进 vue2 项目的 `/public` 中。\n\n在 `/public/index.html` 中引用字体入口文件：\n\n```html\n\u003clink href=\"\u003c%= BASE_URL %\u003enoto-sans-sc/noto-sans-sc.css\" rel=\"stylesheet\"\u003e\n```\n\n然后在需要的地方设置字体 font-family 即可：\n\n```css\n#app {\n  font-family: 'Noto Sans SC', sans-serif;\n}\n```\n\n**vue3（vite）**\n\n将下载好的字体文件夹复制进 vite 项目的 `/public` 中。\n\n在 `/index.html` 中引用字体入口文件：\n\n```html\n\u003c!-- 注意 vite 项目直接从根目录引用 public 中的文件即可 --\u003e\n\u003clink href=\"/noto-sans-sc/noto-sans-sc.css\" rel=\"stylesheet\"\u003e\n```\n\n最后在需要的地方设置字体 font-family 即可。\n\n**react（create-react-app）**\n\n首先将下载好的字体文件夹复制进 react 项目的 `/public` 中。\n\n然后在 `/public/index.html` 中引用字体入口文件：\n\n```html\n\u003clink href=\"%PUBLIC_URL%/noto-sans-sc/noto-sans-sc.css\" rel=\"stylesheet\"\u003e\n```\n\n最后在需要的地方设置字体 font-family 即可。\n\n## 许可\n\n详见 [google-fonts license](https://github.com/google/fonts#license)。\n\n## 参考\n\n本工具使用如下依赖开发:\n[fs-extra](https://github.com/jprichardson/node-fs-extra)\n[chalk](note.youdao.com/web/#/file/B32A092E6C2E45DDB3CED7097A92057C/markdown/9E130E1FE7374FAC8579C1CC0B85B96E/)\n[node-fetch](https://www.npmjs.com/package/node-fetch)\n[css-tree](https://github.com/csstree/csstree)。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhopgoldy%2Fgoogle-font-splitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhopgoldy%2Fgoogle-font-splitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhopgoldy%2Fgoogle-font-splitter/lists"}