@fluentui/react-icons-font-subsetting-webpack-plugin

中文文档
2.0.346发布于 2026/11/14MITTypeScriptCommonJS近 30 天下载 4901

Webpack plugin to subset the icon fonts used by @fluentui/react-icons based on which icons are used.

原始使用文档
文档目录11 节
  1. Supported Import Patterns
  2. 1. Using the fluentIconFont condition
  3. 2. Using atomic imports from @fluentui/react-icons/fonts/*
  4. 3. Using headless atomic imports from @fluentui/react-icons…
  5. Usage
  6. With fluentIconFont condition
  7. With atomic imports (no conditionNames required)
  8. With rspack
  9. Options
  10. onDuplicateInstances
  11. Development Checks

@fluentui/react-icons-font-subsetting-webpack-plugin

This package includes a plugin for webpack@>=5.0.0 and @rspack/core@>=2.0.0 to subset the icon font files used by @fluentui/react-icons when using font-based icon implementations.

If optimization.usedExports is enabled (as it is by default in production mode), this plugin will subset the font files to only include the glyphs actually used by your build.

Supported Import Patterns

The plugin supports the following import patterns from @fluentui/react-icons:

1. Using the fluentIconFont condition

// Uses font implementation via resolve.conditionNames
import { AddRegular, DeleteFilled } from '@fluentui/react-icons';

2. Using atomic imports from @fluentui/react-icons/fonts/*

// Direct atomic imports - no conditionNames required
import { AddRegular, AddFilled } from '@fluentui/react-icons/fonts/add';
import { DeleteRegular } from '@fluentui/react-icons/fonts/delete';

Atomic imports provide better tree-shaking and faster build times for applications using a small number of icons.

3. Using headless atomic imports from @fluentui/react-icons/headless/fonts/*

// Headless font atoms — no Griffel runtime.
// You MUST also import the headless font CSS so the @font-face declarations and
// font files enter the module graph (the headless atoms don't import them):
import '@fluentui/react-icons/headless/fonts/styles.css';
import { AddRegular, AddFilled } from '@fluentui/react-icons/headless/fonts/add';

The plugin subsets the same shared font files used by the standard API, based on the headless icons you actually use. Because the font files arrive via styles.css, your config needs a CSS loader (e.g. css-loader) so the url(...) references resolve into webpack assets.

Tip 💡: You don't have to write atomic headless imports by hand. Pair this plugin with @fluentui/react-icons-atomic-webpack-loader using { headless: true, iconVariant: 'fonts' } — it rewrites plain barrel imports (import { AddFilled } from '@fluentui/react-icons') into headless font atoms, which this plugin then subsets. You still import @fluentui/react-icons/headless/fonts/styles.css yourself.

The plugin is query-aware for the atomic loader's moduleGranularity: 'icon' mode. Queried modules are attributed through their query-free physical paths while their exact selected exports are aggregated. Use coordinated loader/plugin releases: the two packages perform a compilation-level v1 selector capability handshake and fail the build instead of producing an incorrect subset when support is missing or incompatible.

Usage

With fluentIconFont condition

// webpack.config.js
const {
  default: FluentUIReactIconsFontSubsettingPlugin,
} = require('@fluentui/react-icons-font-subsetting-webpack-plugin');

module.exports = {
  module: {
    rules: [
      // Treat the font files as webpack assets
      {
        test: /\.(ttf|woff2?)$/,
        type: 'asset',
      },
    ],
  },
  resolve: {
    // Include 'fluentIconFont' to use the font implementation of the Fluent icons
    conditionNames: ['fluentIconFont', 'import'],
  },
  plugins: [
    // Include this plugin
    new FluentUIReactIconsFontSubsettingPlugin(),
  ],
};

With atomic imports (no conditionNames required)

// webpack.config.js
const {
  default: FluentUIReactIconsFontSubsettingPlugin,
} = require('@fluentui/react-icons-font-subsetting-webpack-plugin');

module.exports = {
  module: {
    rules: [
      // Treat the font files as webpack assets
      {
        test: /\.(ttf|woff2?)$/,
        type: 'asset',
      },
    ],
  },
  plugins: [
    // Include this plugin
    new FluentUIReactIconsFontSubsettingPlugin(),
  ],
};

With rspack

The plugin is bundler-agnostic and works unchanged in rspack — the same configuration applies:

// rspack.config.js
const {
  default: FluentUIReactIconsFontSubsettingPlugin,
} = require('@fluentui/react-icons-font-subsetting-webpack-plugin');

module.exports = {
  module: {
    rules: [
      {
        test: /\.(ttf|woff2?)$/,
        type: 'asset',
      },
    ],
  },
  plugins: [new FluentUIReactIconsFontSubsettingPlugin()],
};

Two rspack-specific notes:

  • For the headless import pattern, use rspack.CssExtractRspackPlugin instead of mini-css-extract-plugin, which is not compatible with rspack.
  • webpack and @rspack/core are both declared as optional peer dependencies, so you only need to install the bundler you actually use.

rspack >=2.0.0 is required because subsetting reads the module graph, and moduleGraph.getUsedExports() was exposed to the JS API in rspack 2.0.0.

On rspack 2.0.x there is one limitation: moduleGraph.getProvidedExports() only landed in 2.1.0, and it is what lets the plugin subset icons reached through a namespace import (import * as Icons from '@fluentui/react-icons/fonts/…'). Because those icons cannot be identified, every font in the affected package is left un-subset — not just the namespace import's own module — since subsetting from the package's remaining imports would drop glyphs the namespace import actually uses. A build warning names the package when this happens. Named imports — the common case — are unaffected and subset fully. Upgrade to rspack >=2.1.0 for complete coverage.

Options

onDuplicateInstances

'warn' | 'error', default 'warn'.

The plugin subsets against one resolved @fluentui/react-icons package instance. When font modules resolve from more than one installed copy — peer-dependency variants in a virtual store will do this without any version conflict — emitted font assets cannot be attributed safely to one coherent source.

The plugin detects multiple participating copies before inspecting font-asset ownership, leaves all fonts un-subset so every glyph still renders, and warns with the paths involved. Set 'error' to fail the build instead:

new FluentUIReactIconsFontSubsettingPlugin({ onDuplicateInstances: 'error' });

To get subsetting back, collapse the copies onto one instance with bundler resolve.alias entries. Note that this also binds every copy to a single React and Griffel instance.

Using ESM import and CommonJS require() from the same installation does not count as two copies. Their used exports are combined, and each emitted font asset is subset once.

Development Checks

Run yarn nx run react-icons-font-subsetting-webpack-plugin:test for unit, type, and webpack/rspack integration coverage.

Run yarn nx run react-icons-font-subsetting-webpack-plugin:test:render for the localized full/subset font browser check. It requires Playwright Chromium (yarn playwright install chromium) and checks standard/headless rendering, LTR/RTL contexts, and desktop/mobile viewports. Screenshots are written to tmp/localized-font-render at the repository root.

版本与发布记录

@fluentui/react-icons-font-subsetting-webpack-plugin 共发布 155 个版本,首次发布于 2022/05/17;过去 12 个月发布了 36 个版本。

版本发布日期距今
2.0.346latest2026/11/142 天前
2.0.3452026/10/3116 天前
2.0.3442026/10/101 个月前
2.0.3432026/09/261 个月前
2.0.3422026/09/251 个月前
2.0.3412026/09/122 个月前

其他发布通道:rc → 2.0.173-rc.9,prerelease → 2.0.324-alpha.1。

关于 @fluentui/react-icons-font-subsetting-webpack-plugin 的常见问题

@fluentui/react-icons-font-subsetting-webpack-plugin 是什么?

Webpack plugin to subset the icon fonts used by @fluentui/react-icons based on which icons are used.

如何安装 @fluentui/react-icons-font-subsetting-webpack-plugin?

在项目目录运行 npm install @fluentui/react-icons-font-subsetting-webpack-plugin,或使用 pnpm add / yarn add / bun add。

@fluentui/react-icons-font-subsetting-webpack-plugin 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@fluentui/react-icons-font-subsetting-webpack-plugin 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@fluentui/react-icons-font-subsetting-webpack-plugin 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.5.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@fluentui/react-icons-font-subsetting-webpack-plugin 可以商用吗?

@fluentui/react-icons-font-subsetting-webpack-plugin 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fluentui/react-icons-font-subsetting-webpack-plugin 的下载量有多少?

根据 npm 官方下载统计,@fluentui/react-icons-font-subsetting-webpack-plugin 在 2026/10/15 – 2026/11/13 这 30 天内被下载 4,901 次,日均约 163 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fluentui/react-icons-font-subsetting-webpack-plugin 还在维护吗?

最新版本 2.0.346 发布于 2026/11/14(2 天前);至今共发布 155 个版本,其中过去 12 个月发布了 36 个;首次发布于 2022/05/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。