Vite Plugin SVG Icons 使用教程

Vite Plugin SVG Icons 使用教程

vite-plugin-svg-iconsVite Plugin for fast creating SVG sprites.项目地址:https://gitcode.com/gh_mirrors/vi/vite-plugin-svg-icons

1. 项目的目录结构及介绍

vite-plugin-svg-icons/
├── README.md
├── package.json
├── src/
│   ├── index.ts
│   ├── plugin.ts
│   └── utils/
│       ├── cache.ts
│       └── dom.ts
├── tsconfig.json
└── vite.config.ts
  • README.md: 项目说明文档,包含安装和使用说明。
  • package.json: 项目依赖和脚本配置文件。
  • src/: 源代码目录。
    • index.ts: 插件入口文件。
    • plugin.ts: 插件核心逻辑。
    • utils/: 工具函数目录。
      • cache.ts: 缓存管理工具。
      • dom.ts: DOM 操作工具。
  • tsconfig.json: TypeScript 配置文件。
  • vite.config.ts: Vite 配置文件。

2. 项目的启动文件介绍

项目的启动文件主要是 src/index.ts,它是插件的入口文件,负责导出插件的主要功能。

// src/index.ts
import { createSvgIconsPlugin } from './plugin';

export { createSvgIconsPlugin };

3. 项目的配置文件介绍

vite.config.ts

vite.config.ts 是 Vite 项目的配置文件,用于配置 Vite 的行为。在这个项目中,它用于配置 SVG 图标插件。

// vite.config.ts
import { defineConfig } from 'vite';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import path from 'path';

export default defineConfig({
  plugins: [
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/icons')],
      symbolId: 'icon-[dir]-[name]',
      inject: 'body-last',
      customDomId: '__svg__icons__dom__',
    }),
  ],
});

tsconfig.json

tsconfig.json 是 TypeScript 项目的配置文件,用于配置 TypeScript 编译器的行为。

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "strict": true,
    "jsx": "preserve",
    "sourceMap": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "lib": ["esnext", "dom"]
  },
  "include": ["src"]
}

以上是 Vite Plugin SVG Icons 项目的目录结构、启动文件和配置文件的介绍。希望这份文档能帮助你更好地理解和使用这个开源项目。

vite-plugin-svg-iconsVite Plugin for fast creating SVG sprites.项目地址:https://gitcode.com/gh_mirrors/vi/vite-plugin-svg-icons

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

褚知茉Jade

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值