svgIcons(options?)
把 SVG 目录编译为独立 Vue TSX 组件及根索引。每个 SVG 生成到根索引所在目录的 <SVG 相对路径>/index.tsx,组件使用 defineComponent 和内联 SVG JSX,消费项目必须启用 Vue JSX/TSX 转换。
ts
svgIcons({
dir: "src/assets/icons",
output: "src/icons/index.ts",
componentPrefix: "App",
removeDimensions: true,
defaultAttributes: { "aria-hidden": "true", focusable: false },
});| 选项 | 默认值 | 说明 |
|---|---|---|
dir | "src/assets/icons" | SVG 源目录 |
output | "src/icons/index.ts" | 图标根索引 |
deep | true | 是否递归 |
componentPrefix | "" | 组件名前缀 |
componentSuffix | "" | 组件名后缀 |
include / name | - | 文件过滤器 / 命名器 |
defaultAttributes | {} | 默认根属性,源 SVG 同名属性优先 |
removeDimensions | false | 删除 width / height |
debounce | 80 | 开发监听防抖毫秒数 |
SVG 标记会直接写入生成的 TSX 源码。不要把用户上传或其他不可信 SVG 放入扫描目录。
根索引提供每个图标的命名导出,并通过 export default { ... } as const 直接默认导出只读组件对象,不生成中间 icons 变量。
svgIcons 图标生成
将 SVG 目录编译为独立的 Vue 图标组件与根索引。
生成组件通过 defineComponent 与内联 SVG JSX 渲染,消费项目需要启用 Vue JSX/TSX 转换。
签名
ts
export function svgIcons(options: SvgIconsPluginOptions = {}): Plugin;示例
ts
import { svgIcons } from "fast-vite-plugins";
const plugin = svgIcons({ dir: "src/assets/icons", output: "src/icons/index.ts" });
export default { plugins: [plugin] };输入
| 输入值 | 输入值类型 | 必填/默认值 | 输入值说明 |
|---|---|---|---|
options | SvgIconsPluginOptions | 否,默认 {} | SVG 目录、输出文件、命名、过滤和根属性配置。 |
返回
| 返回值 | 返回值类型 | 返回值说明 |
|---|---|---|
plugin | Plugin | 可直接加入 Vite plugins 的 SVG 图标生成插件。 |
