vite-svg-sprite-generator-plugin 1.1.7 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-svg-sprite-generator-plugin",
3
- "version": "1.1.7",
4
- "description": "Production-ready Vite plugin for automatic SVG sprite generation with HMR support, SVGO optimization, and security features",
3
+ "version": "1.3.0",
4
+ "description": "Production-ready Vite plugin for automatic SVG sprite generation with HMR support, SVGO optimization, security features, and tree-shaking",
5
5
  "main": "vite-svg-sprite-generator-plugin.js",
6
6
  "module": "vite-svg-sprite-generator-plugin.js",
7
7
  "types": "vite-svg-sprite-generator-plugin.d.ts",
@@ -17,8 +17,7 @@
17
17
  "vite-svg-sprite-generator-plugin.ts",
18
18
  "vite-svg-sprite-generator-plugin.d.ts",
19
19
  "README.md",
20
- "LICENSE",
21
- "CHANGELOG.md"
20
+ "LICENSE"
22
21
  ],
23
22
  "scripts": {
24
23
  "prepublishOnly": "npm test",
@@ -30,14 +29,21 @@
30
29
  "svg",
31
30
  "svg-sprite",
32
31
  "sprite-generator",
33
- "svgo",
34
- "sprite",
35
32
  "icons",
33
+ "icon-generator",
34
+ "react",
35
+ "vue",
36
+ "svelte",
37
+ "nuxt",
38
+ "ssr",
39
+ "ssg",
36
40
  "optimization",
41
+ "svgo",
37
42
  "hmr",
38
43
  "hot-reload",
39
- "symbol",
40
- "use"
44
+ "tree-shaking",
45
+ "bundle-optimization",
46
+ "production"
41
47
  ],
42
48
  "author": "Karev G.S.",
43
49
  "license": "MIT",
@@ -1,14 +1,32 @@
1
1
  /**
2
2
  * Vite SVG Sprite Plugin - TypeScript Definitions (Production-Ready)
3
- * @version 1.1.1 - Cross-platform path handling with vite.normalizePath
3
+ * @version 1.3.0 - Aligned with Vite best practices
4
4
  */
5
5
 
6
6
  import type { Plugin } from 'vite';
7
7
 
8
+ // HMR Custom Events Type Definitions
9
+ import 'vite/types/customEvent.d.ts';
10
+
11
+ declare module 'vite/types/customEvent.d.ts' {
12
+ interface CustomEventMap {
13
+ /**
14
+ * Custom HMR event for SVG sprite updates
15
+ * Fired when icons are added/removed/modified in dev mode
16
+ */
17
+ 'svg-sprite-update': {
18
+ /** Complete SVG sprite content */
19
+ spriteContent: string;
20
+ /** Number of icons in the sprite */
21
+ iconCount: number;
22
+ };
23
+ }
24
+ }
25
+
8
26
  /**
9
27
  * Опции плагина SVG Sprite
10
28
  */
11
- export interface SvgSpritePluginOptions {
29
+ export interface SvgSpriteOptions {
12
30
  /**
13
31
  * Папка с SVG иконками
14
32
  * @default 'src/icons'
@@ -18,14 +36,14 @@ export interface SvgSpritePluginOptions {
18
36
 
19
37
  /**
20
38
  * ID элемента спрайта в DOM
21
- * @default 'icon-sprite'
39
+ * @default 'sprite-id'
22
40
  * @example 'my-sprite'
23
41
  */
24
42
  spriteId?: string;
25
43
 
26
44
  /**
27
45
  * CSS класс спрайта
28
- * @default 'svg-sprite'
46
+ * @default 'sprite-class'
29
47
  * @example 'custom-sprite'
30
48
  */
31
49
  spriteClass?: string;
@@ -38,13 +56,6 @@ export interface SvgSpritePluginOptions {
38
56
  */
39
57
  idPrefix?: string;
40
58
 
41
- /**
42
- * Enable optimization (legacy option)
43
- * @default true
44
- * @deprecated Use svgoOptimize instead for better control
45
- */
46
- optimize?: boolean;
47
-
48
59
  /**
49
60
  * Включить отслеживание изменений в dev-режиме
50
61
  * @default true
@@ -59,13 +70,13 @@ export interface SvgSpritePluginOptions {
59
70
 
60
71
  /**
61
72
  * Подробное логирование
62
- * @default true в development, false в production
73
+ * @default true (когда NODE_ENV === 'development'), false в остальных случаях
63
74
  */
64
75
  verbose?: boolean;
65
76
 
66
77
  /**
67
78
  * Оптимизация SVG с помощью SVGO
68
- * @default true в production, false в development
79
+ * @default true (когда NODE_ENV === 'production'), false в остальных случаях
69
80
  */
70
81
  svgoOptimize?: boolean;
71
82
 
@@ -74,16 +85,46 @@ export interface SvgSpritePluginOptions {
74
85
  * @default оптимальные настройки для спрайтов
75
86
  */
76
87
  svgoConfig?: any;
77
- }
78
88
 
79
- /**
80
- * Информация об иконке в спрайте
81
- */
82
- export interface SpriteIcon {
83
- /** Уникальный ID символа */
84
- id: string;
85
- /** Относительный путь к файлу */
86
- file: string;
89
+ /**
90
+ * Конвертировать цвета заливки и обводки в currentColor
91
+ * Позволяет управлять цветом иконок через CSS
92
+ * @default true
93
+ * @example
94
+ * // С currentColor: true
95
+ * // <path fill="#000" /> → <path fill="currentColor" />
96
+ * // Теперь можно: .icon { color: red; }
97
+ */
98
+ currentColor?: boolean;
99
+
100
+ /**
101
+ * Tree-shaking: включать только используемые иконки
102
+ * Сканирует HTML/JS/TS файлы проекта и находит все <use href="#iconId">
103
+ * Работает ТОЛЬКО в production режиме (vite build)
104
+ * В dev режиме включены все иконки для удобства разработки
105
+ * @default false
106
+ * @example
107
+ * ```ts
108
+ * // vite.config.ts
109
+ * svgSpritePlugin({
110
+ * iconsFolder: 'src/icons',
111
+ * treeShaking: true, // Включить tree-shaking
112
+ * verbose: true // Показать статистику
113
+ * })
114
+ *
115
+ * // index.html (только эти иконки попадут в спрайт)
116
+ * <svg><use href="#home"></use></svg>
117
+ * <svg><use href="#user"></use></svg>
118
+ * ```
119
+ */
120
+ treeShaking?: boolean;
121
+
122
+ /**
123
+ * Расширения файлов для сканирования при tree-shaking
124
+ * @default ['.html', '.js', '.ts', '.jsx', '.tsx', '.vue', '.svelte']
125
+ * @example ['.html', '.js', '.ts'] // Сканировать только эти типы файлов
126
+ */
127
+ scanExtensions?: string[];
87
128
  }
88
129
 
89
130
  /**
@@ -99,74 +140,12 @@ export interface SpriteIcon {
99
140
  * svgSpritePlugin({
100
141
  * iconsFolder: 'src/icons',
101
142
  * spriteId: 'icon-sprite',
102
- * verbose: true
143
+ * verbose: true,
144
+ * svgoOptimize: true
103
145
  * })
104
146
  * ]
105
147
  * });
106
148
  * ```
107
149
  */
108
- export default function svgSpritePlugin(options?: SvgSpritePluginOptions): Plugin;
109
-
110
- /**
111
- * Виртуальный модуль для программного доступа к спрайту
112
- *
113
- * @example
114
- * ```ts
115
- * import { getIconHref, icons, useIcon } from 'virtual:svg-sprite';
116
- *
117
- * // Получить href для иконки
118
- * const href = getIconHref('home'); // '#icon-home'
119
- *
120
- * // Список всех доступных иконок
121
- * console.log(icons); // [{ id: 'icon-home', file: 'src/icons/home.svg' }, ...]
122
- *
123
- * // Создать SVG элемент
124
- * const svg = useIcon('home', { width: 24, height: 24 });
125
- * ```
126
- */
127
- declare module 'virtual:svg-sprite' {
128
- /**
129
- * ID спрайта в DOM
130
- */
131
- export const spriteId: string;
132
-
133
- /**
134
- * Список всех доступных иконок
135
- */
136
- export const icons: SpriteIcon[];
137
-
138
- /**
139
- * Получить href для использования в <use>
140
- * @param name Имя иконки (без префикса)
141
- * @returns href строка, например '#icon-home'
142
- *
143
- * @example
144
- * ```ts
145
- * const href = getIconHref('home');
146
- * // '<svg><use href="#icon-home"></use></svg>'
147
- * ```
148
- */
149
- export function getIconHref(name: string): string;
150
-
151
- /**
152
- * Создать SVG элемент с иконкой
153
- * @param name Имя иконки (без префикса)
154
- * @param attrs Атрибуты для SVG элемента
155
- * @returns HTML строка с SVG элементом
156
- *
157
- * @example
158
- * ```ts
159
- * const svg = useIcon('home', {
160
- * width: 24,
161
- * height: 24,
162
- * fill: 'currentColor'
163
- * });
164
- * document.body.innerHTML += svg;
165
- * ```
166
- */
167
- export function useIcon(
168
- name: string,
169
- attrs?: Record<string, string | number>
170
- ): string;
171
- }
150
+ export default function svgSpritePlugin(options?: SvgSpriteOptions): Plugin;
172
151