@deathmaz/phosphor-icons-vue-split

中文文档
0.2.1发布于 2026/04/09MITTypeScriptES Module零依赖近 30 天下载 2796

Phosphor Icons for Vue 3 with per-weight components for optimal tree-shaking

原始使用文档
文档目录14 节
  1. Installation
  2. Usage
  3. Props
  4. Context provider
  5. Slots
  6. Attrs passthrough
  7. TypeScript
  8. Bundle size
  9. Development
  10. Prerequisites
  11. Setup
  12. Scripts
  13. How it works
  14. License

@deathmaz/phosphor-icons-vue-split

Phosphor Icons for Vue 3 with per-weight components for optimal tree-shaking.

The original @phosphor-icons/vue bundles all 6 weights inside each icon component. Even if you only use the "regular" weight, the SVG data for all other weights is included in your bundle. This library splits each weight into its own component, so you only pay for what you use.

Installation

npm install @deathmaz/phosphor-icons-vue-split

Requires Vue 3.2.39 or later as a peer dependency.

Usage

<script lang="ts" setup>
import {
  PhHorseRegular,
  PhHeartFill,
  PhCubeDuotone,
} from "@deathmaz/phosphor-icons-vue-split";
</script>

<template>
  <PhHorseRegular />
  <PhHeartFill :size="32" color="hotpink" />
  <PhCubeDuotone :size="48" color="#333" />
</template>

Components follow the naming pattern Ph[IconName][Weight], where weight is one of:

WeightExample
ThinPhHeartThin
LightPhHeartLight
RegularPhHeartRegular
BoldPhHeartBold
FillPhHeartFill
DuotonePhHeartDuotone

All Phosphor icons are available across all 6 weights.

Props

All props are optional.

PropTypeDefaultDescription
sizestring | number"1em"Width and height of the SVG
colorstring"currentColor"Fill color of the SVG
mirroredboolean—Horizontally flip the icon (for RTL)
<PhArrowRightBold :size="24" color="red" :mirrored="true" />

Context provider

Use Vue's provide to set defaults for all icons in a subtree, avoiding repetitive props:

<script lang="ts" setup>
import { provide } from "vue";
import { PhHouseRegular, PhGearRegular } from "@deathmaz/phosphor-icons-vue-split";

provide("size", "24px");
provide("color", "#1a1a1a");
provide("mirrored", false);
</script>

<template>
  <!-- Both icons inherit size="24px" and color="#1a1a1a" -->
  <PhHouseRegular />
  <PhGearRegular />
</template>

Props on individual components override the injected context values.

Slots

Components accept a default slot for injecting arbitrary SVG elements (e.g., <title> for accessibility, <animate>, <filter>):

<PhHeartFill :size="32" color="red">
  <title>Favorite</title>
</PhHeartFill>

Attrs passthrough

Any additional attributes are forwarded to the root <svg> element via v-bind="$attrs":

<PhStarFill class="icon" data-testid="star" />

TypeScript

All components are fully typed. A general PhosphorIconComponent type covers any icon, while weight-specific branded types let you constrain props to a single weight:

import type {
  PhosphorIconComponent,
  PhosphorThinIcon,
  PhosphorRegularIcon,
  PhosphorFillIcon,
} from "@deathmaz/phosphor-icons-vue-split";

// Accept any icon
defineProps<{ icon: PhosphorIconComponent }>();

// Accept only regular-weight icons
defineProps<{ icon: PhosphorRegularIcon }>();

Available weight types: PhosphorThinIcon, PhosphorLightIcon, PhosphorRegularIcon, PhosphorBoldIcon, PhosphorFillIcon, PhosphorDuotoneIcon.

Bundle size

Each component contains only its weight's SVG path data. A typical component compiles to ~0.8 KB (gzipped), compared to ~4.4 KB per icon in the original library that bundles all weights.

The library uses sideEffects: false and Vite's preserveModules output, so bundlers can tree-shake unused components at the module level.

Development

Prerequisites

  • Node.js >= 20
  • npm

Setup

npm install

Scripts

ScriptDescription
npm run buildFull pipeline: generate components + Vite build + type definitions
npm run assembleGenerate Vue SFCs from @phosphor-icons/core SVGs
npm run testRun tests with Vitest
npm run test:watchRun tests in watch mode
npm run lintLint with oxlint
npm run typecheckType-check with TypeScript
npm run checkRun typecheck + lint + build + test

How it works

  1. npm run assemble reads SVG files from @phosphor-icons/core (installed as a dev dependency) and generates one Vue SFC per icon per weight into src/icons/. It also generates src/index.ts with named exports for all components, including alias re-exports from the Phosphor icon metadata.

  2. npm run build runs the assemble step, then builds the library with Vite in library mode (preserveModules: true so each component is a separate .mjs file), and finally generates TypeScript type definitions.

Generated files (src/icons/, src/index.ts, dist/) are gitignored — they are produced fresh from @phosphor-icons/core on each build.

License

MIT — Icon designs by Phosphor Icons.

版本与发布记录

@deathmaz/phosphor-icons-vue-split 共发布 3 个版本,首次发布于 2026/02/28;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.2.1latest2026/04/097 个月前
0.2.02026/03/018 个月前
0.1.02026/02/288 个月前

关于 @deathmaz/phosphor-icons-vue-split 的常见问题

@deathmaz/phosphor-icons-vue-split 是什么?

Phosphor Icons for Vue 3 with per-weight components for optimal tree-shaking

如何安装 @deathmaz/phosphor-icons-vue-split?

在项目目录运行 npm install @deathmaz/phosphor-icons-vue-split,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(>=3.2.39)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@deathmaz/phosphor-icons-vue-split 支持 TypeScript 吗?

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

@deathmaz/phosphor-icons-vue-split 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@deathmaz/phosphor-icons-vue-split 可以商用吗?

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

@deathmaz/phosphor-icons-vue-split 的下载量有多少?

根据 npm 官方下载统计,@deathmaz/phosphor-icons-vue-split 在 2026/10/12 – 2026/11/10 这 30 天内被下载 2,796 次,日均约 93 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@deathmaz/phosphor-icons-vue-split 还在维护吗?

最新版本 0.2.1 发布于 2026/04/09(7 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/02/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。