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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@icon-forger/compiler

v0.0.3

Published

> `icon-forger` 的编译核心,提供 Babel 插件、Webpack 插件以及供上层接入层消费的编译钩子。

Readme

@icon-forger/compiler

icon-forger 的编译核心,提供 Babel 插件、Webpack 插件以及供上层接入层消费的编译钩子。

✨ 功能特性

  • Babel 转换能力:识别来源于 .svg 的 JSX 组件并替换成自定义运行时模板
  • Webpack 收集能力:在构建期收集命中的 SVG 资源
  • 字体生成能力:基于 fantasticon 生成 woff2 和配套 CSS
  • 可扩展钩子:通过 emitIconFontAssets 暴露字体输出目录给上层继续处理

📦 安装

npm install @icon-forger/compiler

yarn 安装

yarn add @icon-forger/compiler

pnpm 安装

pnpm add @icon-forger/compiler

⚙️ 使用

更推荐通过 @icon-forger/taro 间接使用;如果需要自定义接入层,可以组合 Babel 插件与 Webpack 插件:

import template from '@babel/template'
import type { JSXElement } from '@babel/types'
import { IconForgerPlugin } from '@icon-forger/compiler'

const iconForgerBabelPlugin = [
  require.resolve('@icon-forger/compiler/babel'),
  {
    dependRequire: ['import { BaseIcon } from "./base-icon"'],
    templateCode: ({ iconName, attributes }) => {
      const node = template.expression(
        `<BaseIcon name="${iconName}" />`,
        { plugins: ['jsx'] }
      )() as JSXElement

      node.openingElement.attributes.push(...attributes)
      return node
    }
  }
]

export default {
  module: {
    rules: [
      {
        test: /\.[jt]sx?$/,
        use: {
          loader: 'babel-loader',
          options: {
            plugins: [iconForgerBabelPlugin]
          }
        }
      }
    ]
  },
  plugins: [new IconForgerPlugin()]
}

🔧 导出项

| 导出路径 | 说明 | | --- | --- | | @icon-forger/compiler | 导出 IconForgerPlugin、类型定义等核心能力 | | @icon-forger/compiler/babel | Babel 插件入口,用于替换 .svg JSX 组件 | | @icon-forger/compiler/plugin | IconForgerPlugin 单独导出入口 |

📝 工作原理

  1. Babel 插件追踪 JSX 元素的 import 绑定来源
  2. 当绑定来源是 .svg 文件时,替换原 JSX 并注入依赖 import
  3. Webpack 插件在 succeedModule 阶段收集 SVG 源码
  4. processAssets 阶段把 SVG 写入缓存目录并调用 fantasticon 生成字体
  5. 通过 emitIconFontAssets 钩子把字体输出目录暴露给上层接入包继续处理

⚠️ 注意事项

  1. 需要自行提供运行时模板:直接使用 Babel 插件时,必须传入 templateCode 来定义 SVG 替换结果。
  2. 依赖 Webpack 5 与 Babel 7:当前类型和实现都按这套编译基础设施设计。
  3. 缓存目录默认位于 node_modules/.cache/icon-forger:如需隔离缓存,可通过 IconForgerPlugincacheDir 选项覆盖。

📄 许可证

MIT License