vite-svg-sprite-generator-plugin 1.1.1 β 1.1.2
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/CHANGELOG.md +14 -2
- package/README.md +68 -189
- package/package.json +1 -2
- package/vite-svg-sprite-generator-plugin.d.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -25,7 +25,7 @@ All notable changes to this project will be documented in this file.
|
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
28
|
-
## [1.1.0] - 2025-10-
|
|
28
|
+
## [1.1.0] - 2025-10-25
|
|
29
29
|
|
|
30
30
|
### π Security
|
|
31
31
|
|
|
@@ -91,7 +91,19 @@ No changes required for existing users. All improvements are transparent.
|
|
|
91
91
|
|
|
92
92
|
---
|
|
93
93
|
|
|
94
|
-
## [1.0.
|
|
94
|
+
## [1.0.1] - 2025-10-24
|
|
95
|
+
|
|
96
|
+
### π¨ Documentation & Improvements
|
|
97
|
+
|
|
98
|
+
- **IMPROVED:** Updated README with inline SVG behavior documentation
|
|
99
|
+
- **ADDED:** Clarification that sprite is injected into page DOM
|
|
100
|
+
- **ADDED:** "How It Works" section in README
|
|
101
|
+
- **ADDED:** "Why Inline SVG?" section explaining benefits
|
|
102
|
+
- **IMPROVED:** Better documentation of sprite injection behavior
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## [1.0.0] - 2025-10-23
|
|
95
107
|
|
|
96
108
|
### π Initial Release
|
|
97
109
|
|
package/README.md
CHANGED
|
@@ -11,10 +11,13 @@
|
|
|
11
11
|
- β‘ **Hot Module Replacement** - Instant updates without page reload during development
|
|
12
12
|
- π **Security First** - Built-in XSS protection and path traversal prevention
|
|
13
13
|
- πΎ **Smart Caching** - Efficient caching with mtime-based validation
|
|
14
|
-
- π― **Auto-Injection** -
|
|
14
|
+
- π― **Auto-Injection** - Sprite is automatically injected into HTML as inline SVG (no separate file)
|
|
15
|
+
- π **Inline SVG** - Sprite is inserted directly into the page DOM, no external requests
|
|
15
16
|
- π§ **Fully Configurable** - Extensive customization options
|
|
16
17
|
- π¦ **Zero Config** - Works out of the box with sensible defaults
|
|
17
18
|
- π³ **Tree-Shakeable** - ES modules with proper exports
|
|
19
|
+
- π¨ **Vite Standard Compliance** - Fully complies with Vite plugin API and ecosystem standards
|
|
20
|
+
- π **Uses Vite Utilities** - Leverages `vite.normalizePath` for consistent cross-platform path handling
|
|
18
21
|
|
|
19
22
|
## π¦ Installation
|
|
20
23
|
|
|
@@ -92,6 +95,45 @@ src/
|
|
|
92
95
|
|
|
93
96
|
That's it! π
|
|
94
97
|
|
|
98
|
+
## π¨ How It Works
|
|
99
|
+
|
|
100
|
+
The plugin automatically **injects the sprite directly into your HTML** as an inline SVG element.
|
|
101
|
+
|
|
102
|
+
β
**No separate file generated** - Sprite is embedded in the page DOM
|
|
103
|
+
β
**No external requests** - Everything works in a single HTTP request
|
|
104
|
+
β
**Automatic injection** - Sprite appears in HTML automatically
|
|
105
|
+
β
**Fast rendering** - Icons display immediately, no loading delay
|
|
106
|
+
|
|
107
|
+
### Where is the sprite?
|
|
108
|
+
|
|
109
|
+
Look for this in your HTML:
|
|
110
|
+
|
|
111
|
+
```html
|
|
112
|
+
<svg id="icon-sprite" class="svg-sprite" xmlns="http://www.w3.org/2000/svg">
|
|
113
|
+
<defs>
|
|
114
|
+
<symbol id="home">...</symbol>
|
|
115
|
+
<symbol id="user">...</symbol>
|
|
116
|
+
</defs>
|
|
117
|
+
</svg>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The sprite is **injected at the end of your HTML** (just before `</body>` tag).
|
|
121
|
+
|
|
122
|
+
## π¨ Vite Compliance
|
|
123
|
+
|
|
124
|
+
This plugin is built with maximum compliance to Vite standards and best practices:
|
|
125
|
+
|
|
126
|
+
- β
**Official Vite Plugin API** - Implements all required hooks (`buildStart`, `buildEnd`, `configureServer`, `handleHotUpdate`)
|
|
127
|
+
- β
**Uses Vite Internal Utilities** - Leverages `vite.normalizePath` for cross-platform path normalization
|
|
128
|
+
- β
**Vite HMR Integration** - Properly integrates with Vite's HMR system for instant updates
|
|
129
|
+
- β
**Vite Config Integration** - Respects all Vite configuration options (mode, command, etc.)
|
|
130
|
+
- β
**Async/Await Standards** - Uses modern async patterns following Vite conventions
|
|
131
|
+
- β
**TypeScript Support** - Full TypeScript definitions for better DX
|
|
132
|
+
- β
**No Breaking Changes** - Follows semantic versioning and Vite ecosystem standards
|
|
133
|
+
- β
**Zero Vite Configuration Override** - Doesn't interfere with other Vite plugins or features
|
|
134
|
+
|
|
135
|
+
The plugin seamlessly integrates into your Vite workflow without any conflicts.
|
|
136
|
+
|
|
95
137
|
## π Documentation
|
|
96
138
|
|
|
97
139
|
### Options
|
|
@@ -280,35 +322,6 @@ Advanced SVG sanitization with precompiled RegExp patterns:
|
|
|
280
322
|
</svg>
|
|
281
323
|
```
|
|
282
324
|
|
|
283
|
-
### CSS Styling
|
|
284
|
-
|
|
285
|
-
```css
|
|
286
|
-
/* Basic styling */
|
|
287
|
-
.icon {
|
|
288
|
-
width: 24px;
|
|
289
|
-
height: 24px;
|
|
290
|
-
fill: currentColor;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/* Color variants */
|
|
294
|
-
.icon-primary {
|
|
295
|
-
fill: #007bff;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
.icon-danger {
|
|
299
|
-
fill: #dc3545;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/* With transitions */
|
|
303
|
-
.icon {
|
|
304
|
-
transition: fill 0.3s ease;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
.icon:hover {
|
|
308
|
-
fill: #0056b3;
|
|
309
|
-
}
|
|
310
|
-
```
|
|
311
|
-
|
|
312
325
|
### React/Vue/Svelte
|
|
313
326
|
|
|
314
327
|
```jsx
|
|
@@ -359,6 +372,8 @@ defineProps(['name']);
|
|
|
359
372
|
</svg>
|
|
360
373
|
```
|
|
361
374
|
|
|
375
|
+
---
|
|
376
|
+
|
|
362
377
|
## π Performance
|
|
363
378
|
|
|
364
379
|
### Optimization Results
|
|
@@ -379,117 +394,16 @@ sun.svg : 305 β 287 bytes (-5.9%)
|
|
|
379
394
|
|
|
380
395
|
**Average reduction: 40-50%** π
|
|
381
396
|
|
|
382
|
-
##
|
|
383
|
-
|
|
384
|
-
### HMR Support
|
|
385
|
-
|
|
386
|
-
The plugin includes built-in Hot Module Replacement support:
|
|
387
|
-
|
|
388
|
-
- β
Add new icons β instant update
|
|
389
|
-
- β
Modify icons β instant update
|
|
390
|
-
- β
Delete icons β instant update
|
|
391
|
-
- β
No page reload needed
|
|
392
|
-
|
|
393
|
-
### Security Features
|
|
394
|
-
|
|
395
|
-
- β
XSS protection (removes `<script>` tags)
|
|
396
|
-
- β
Event handler removal
|
|
397
|
-
- β
JavaScript URL filtering
|
|
398
|
-
- β
Path traversal prevention
|
|
399
|
-
- β
File size limits (5MB max)
|
|
400
|
-
|
|
401
|
-
### Caching
|
|
402
|
-
|
|
403
|
-
- β
LRU-like cache with mtime validation
|
|
404
|
-
- β
Automatic cache invalidation
|
|
405
|
-
- β
Memory-efficient (max 500 entries)
|
|
406
|
-
|
|
407
|
-
### Duplicate Detection
|
|
408
|
-
|
|
409
|
-
```
|
|
410
|
-
β οΈ Duplicate symbol ID detected: icon-home from home.svg
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
Automatic detection and handling of duplicate IDs.
|
|
414
|
-
|
|
415
|
-
## π Troubleshooting
|
|
416
|
-
|
|
417
|
-
### Icons Not Showing
|
|
418
|
-
|
|
419
|
-
1. Check that sprite is injected:
|
|
420
|
-
```javascript
|
|
421
|
-
document.getElementById('icon-sprite')
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
2. Verify icon ID (default - no prefix):
|
|
425
|
-
```html
|
|
426
|
-
<use href="#home"></use> <!-- Correct (default) -->
|
|
427
|
-
<use href="#icon-home"></use> <!-- Only if you set idPrefix: 'icon' -->
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
3. Check console for errors
|
|
431
|
-
|
|
432
|
-
4. Inspect sprite to see actual symbol IDs:
|
|
433
|
-
```javascript
|
|
434
|
-
document.querySelectorAll('#icon-sprite symbol')
|
|
435
|
-
```
|
|
436
|
-
|
|
437
|
-
### SVGO Not Installed Warning
|
|
438
|
-
|
|
439
|
-
If you see:
|
|
440
|
-
```
|
|
441
|
-
β οΈ SVGO not installed. Optimization disabled.
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
**Option 1 - Install SVGO (recommended for production):**
|
|
445
|
-
```bash
|
|
446
|
-
npm install -D svgo
|
|
447
|
-
```
|
|
448
|
-
|
|
449
|
-
**Option 2 - Disable the warning:**
|
|
450
|
-
```javascript
|
|
451
|
-
svgSpritePlugin({
|
|
452
|
-
svgoOptimize: false // Don't try to use SVGO
|
|
453
|
-
})
|
|
454
|
-
```
|
|
455
|
-
|
|
456
|
-
**Option 3 - Ignore it:**
|
|
457
|
-
The plugin works fine without SVGO! The warning is just informational.
|
|
458
|
-
|
|
459
|
-
### SVGO Issues
|
|
460
|
-
|
|
461
|
-
If icons look broken after SVGO optimization:
|
|
462
|
-
|
|
463
|
-
```javascript
|
|
464
|
-
svgSpritePlugin({
|
|
465
|
-
svgoOptimize: false // Disable temporarily
|
|
466
|
-
})
|
|
467
|
-
```
|
|
468
|
-
|
|
469
|
-
Or use safer config:
|
|
470
|
-
|
|
471
|
-
```javascript
|
|
472
|
-
svgoConfig: {
|
|
473
|
-
plugins: [
|
|
474
|
-
'preset-default',
|
|
475
|
-
{ name: 'removeViewBox', active: false }
|
|
476
|
-
]
|
|
477
|
-
}
|
|
478
|
-
```
|
|
479
|
-
|
|
480
|
-
### HMR Not Working
|
|
481
|
-
|
|
482
|
-
Ensure `watch: true` is set:
|
|
397
|
+
## π Changelog
|
|
483
398
|
|
|
484
|
-
|
|
485
|
-
svgSpritePlugin({
|
|
486
|
-
watch: true // Should be enabled by default
|
|
487
|
-
})
|
|
488
|
-
```
|
|
399
|
+
### v1.1.1 (2025-10-26)
|
|
489
400
|
|
|
490
|
-
|
|
401
|
+
- π§ **Using `vite.normalizePath`** - Better cross-platform compatibility
|
|
402
|
+
- β‘ Improved Windows/Unix path handling
|
|
403
|
+
- π Better edge case support (network paths, etc.)
|
|
404
|
+
- β
**No Breaking Changes** - Fully backward compatible
|
|
491
405
|
|
|
492
|
-
### v1.1.0 (2025-10-
|
|
406
|
+
### v1.1.0 (2025-10-25)
|
|
493
407
|
|
|
494
408
|
- π **Path Traversal Protection** - Secure path validation
|
|
495
409
|
- β‘ **100% Async FS** - No event loop blocking
|
|
@@ -497,59 +411,24 @@ svgSpritePlugin({
|
|
|
497
411
|
- π **Better Errors** - Detailed messages with examples
|
|
498
412
|
- β
**No Breaking Changes** - Fully backward compatible
|
|
499
413
|
|
|
500
|
-
###
|
|
501
|
-
|
|
502
|
-
- π **SVGO is now OPTIONAL** - Plugin works without it!
|
|
503
|
-
- π¦ Smaller installation (~1.5 MB saved without SVGO)
|
|
504
|
-
- β¨ Automatic SVGO detection with graceful fallback
|
|
505
|
-
- π Dynamic import - SVGO loaded only when available
|
|
506
|
-
- β‘ No breaking changes
|
|
414
|
+
### v1.0.1 (2025-10-24)
|
|
507
415
|
|
|
508
|
-
|
|
416
|
+
- π **Documentation Updates** - Clarified inline SVG behavior
|
|
417
|
+
- π Added "How It Works" section
|
|
418
|
+
- π‘ Added "Why Inline SVG?" section explaining benefits
|
|
509
419
|
|
|
510
|
-
|
|
511
|
-
- Symbol IDs are now just filenames (e.g., `home` instead of `icon-home`)
|
|
420
|
+
### v1.0.0 (2025-10-23)
|
|
512
421
|
|
|
513
|
-
|
|
422
|
+
- π **Initial Release** - Production-ready Vite plugin
|
|
423
|
+
- π SVGO Optimization - 40-60% size reduction
|
|
424
|
+
- β‘ Hot Module Replacement - Instant updates
|
|
425
|
+
- π Security First - XSS protection and path traversal prevention
|
|
426
|
+
- πΎ Smart Caching - LRU-like cache with mtime validation
|
|
427
|
+
- π― Auto-Injection - Automatic sprite injection into HTML
|
|
428
|
+
- π¦ Zero Config - Works out of the box
|
|
429
|
+
- π³ Tree-Shakeable - ES modules with proper exports
|
|
514
430
|
|
|
515
|
-
|
|
516
|
-
- β¨ Automatic optimization in production
|
|
517
|
-
- β¨ Configurable SVGO settings
|
|
518
|
-
- π Fixed memory leak in configureServer
|
|
519
|
-
- π Improved documentation
|
|
520
|
-
|
|
521
|
-
### v3.0.2 (2025-10-26)
|
|
522
|
-
|
|
523
|
-
- π Critical memory leak fix
|
|
524
|
-
- π Enhanced security measures
|
|
525
|
-
- β‘ Performance improvements
|
|
526
|
-
|
|
527
|
-
### v3.0.0
|
|
528
|
-
|
|
529
|
-
- β¨ Complete rewrite with TypeScript
|
|
530
|
-
- β¨ HMR support
|
|
531
|
-
- β¨ Security features
|
|
532
|
-
- β¨ Smart caching
|
|
533
|
-
|
|
534
|
-
## π€ Contributing
|
|
535
|
-
|
|
536
|
-
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
537
|
-
|
|
538
|
-
### Development Setup
|
|
539
|
-
|
|
540
|
-
```bash
|
|
541
|
-
# Clone repository
|
|
542
|
-
git clone https://github.com/german-schneck/vite-svg-sprite-generator-plugin.git
|
|
543
|
-
|
|
544
|
-
# Install dependencies
|
|
545
|
-
npm install
|
|
546
|
-
|
|
547
|
-
# Run tests
|
|
548
|
-
npm test
|
|
549
|
-
|
|
550
|
-
# Build
|
|
551
|
-
npm run build
|
|
552
|
-
```
|
|
431
|
+
For the complete changelog, see [CHANGELOG.md](CHANGELOG.md)
|
|
553
432
|
|
|
554
433
|
## π License
|
|
555
434
|
|
|
@@ -562,8 +441,8 @@ MIT Β© Karev G.S.
|
|
|
562
441
|
|
|
563
442
|
## π§ Support
|
|
564
443
|
|
|
565
|
-
- π [Issues](https://github.com/
|
|
566
|
-
- π¬ [Discussions](https://github.com/
|
|
444
|
+
- π [Issues](https://github.com/gkarev/vite-svg-sprite-generator-plugin/issues)
|
|
445
|
+
- π¬ [Discussions](https://github.com/gkarev/vite-svg-sprite-generator-plugin/discussions)
|
|
567
446
|
|
|
568
447
|
---
|
|
569
448
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-svg-sprite-generator-plugin",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Production-ready Vite plugin for automatic SVG sprite generation with HMR support, SVGO optimization, and security features",
|
|
5
5
|
"main": "vite-svg-sprite-generator-plugin.js",
|
|
6
6
|
"module": "vite-svg-sprite-generator-plugin.js",
|
|
@@ -66,4 +66,3 @@
|
|
|
66
66
|
"node": ">=14.18.0"
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Vite SVG Sprite Plugin - TypeScript Definitions (Production-Ready)
|
|
3
|
-
* @version
|
|
3
|
+
* @version 1.1.1 - Cross-platform path handling with vite.normalizePath
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { Plugin } from 'vite';
|
|
@@ -39,8 +39,9 @@ export interface SvgSpritePluginOptions {
|
|
|
39
39
|
idPrefix?: string;
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Enable optimization (legacy option)
|
|
43
43
|
* @default true
|
|
44
|
+
* @deprecated Use svgoOptimize instead for better control
|
|
44
45
|
*/
|
|
45
46
|
optimize?: boolean;
|
|
46
47
|
|
|
@@ -91,7 +92,7 @@ export interface SpriteIcon {
|
|
|
91
92
|
* @example
|
|
92
93
|
* ```ts
|
|
93
94
|
* import { defineConfig } from 'vite';
|
|
94
|
-
* import svgSpritePlugin from '
|
|
95
|
+
* import svgSpritePlugin from 'vite-svg-sprite-generator-plugin';
|
|
95
96
|
*
|
|
96
97
|
* export default defineConfig({
|
|
97
98
|
* plugins: [
|