vite-svg-sprite-generator-plugin 1.1.1 β 1.1.3
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 +66 -189
- package/package.json +2 -3
- 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,43 @@ 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" style="display: none;">
|
|
113
|
+
<symbol id="home" viewBox="0 0 24 24">...</symbol>
|
|
114
|
+
<symbol id="user" viewBox="0 0 24 24">...</symbol>
|
|
115
|
+
</svg>
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The sprite is **injected at the start of your HTML** (just after `<body>` tag).
|
|
119
|
+
|
|
120
|
+
## π¨ Vite Compliance
|
|
121
|
+
|
|
122
|
+
This plugin is built with maximum compliance to Vite standards and best practices:
|
|
123
|
+
|
|
124
|
+
- β
**Official Vite Plugin API** - Implements all required hooks (`buildStart`, `buildEnd`, `configureServer`, `handleHotUpdate`)
|
|
125
|
+
- β
**Uses Vite Internal Utilities** - Leverages `vite.normalizePath` for cross-platform path normalization
|
|
126
|
+
- β
**Vite HMR Integration** - Properly integrates with Vite's HMR system for instant updates
|
|
127
|
+
- β
**Vite Config Integration** - Respects all Vite configuration options (mode, command, etc.)
|
|
128
|
+
- β
**Async/Await Standards** - Uses modern async patterns following Vite conventions
|
|
129
|
+
- β
**TypeScript Support** - Full TypeScript definitions for better DX
|
|
130
|
+
- β
**No Breaking Changes** - Follows semantic versioning and Vite ecosystem standards
|
|
131
|
+
- β
**Zero Vite Configuration Override** - Doesn't interfere with other Vite plugins or features
|
|
132
|
+
|
|
133
|
+
The plugin seamlessly integrates into your Vite workflow without any conflicts.
|
|
134
|
+
|
|
95
135
|
## π Documentation
|
|
96
136
|
|
|
97
137
|
### Options
|
|
@@ -280,35 +320,6 @@ Advanced SVG sanitization with precompiled RegExp patterns:
|
|
|
280
320
|
</svg>
|
|
281
321
|
```
|
|
282
322
|
|
|
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
323
|
### React/Vue/Svelte
|
|
313
324
|
|
|
314
325
|
```jsx
|
|
@@ -359,6 +370,8 @@ defineProps(['name']);
|
|
|
359
370
|
</svg>
|
|
360
371
|
```
|
|
361
372
|
|
|
373
|
+
---
|
|
374
|
+
|
|
362
375
|
## π Performance
|
|
363
376
|
|
|
364
377
|
### Optimization Results
|
|
@@ -379,117 +392,16 @@ sun.svg : 305 β 287 bytes (-5.9%)
|
|
|
379
392
|
|
|
380
393
|
**Average reduction: 40-50%** π
|
|
381
394
|
|
|
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:
|
|
395
|
+
## π Changelog
|
|
483
396
|
|
|
484
|
-
|
|
485
|
-
svgSpritePlugin({
|
|
486
|
-
watch: true // Should be enabled by default
|
|
487
|
-
})
|
|
488
|
-
```
|
|
397
|
+
### v1.1.1 (2025-10-26)
|
|
489
398
|
|
|
490
|
-
|
|
399
|
+
- π§ **Using `vite.normalizePath`** - Better cross-platform compatibility
|
|
400
|
+
- β‘ Improved Windows/Unix path handling
|
|
401
|
+
- π Better edge case support (network paths, etc.)
|
|
402
|
+
- β
**No Breaking Changes** - Fully backward compatible
|
|
491
403
|
|
|
492
|
-
### v1.1.0 (2025-10-
|
|
404
|
+
### v1.1.0 (2025-10-25)
|
|
493
405
|
|
|
494
406
|
- π **Path Traversal Protection** - Secure path validation
|
|
495
407
|
- β‘ **100% Async FS** - No event loop blocking
|
|
@@ -497,59 +409,24 @@ svgSpritePlugin({
|
|
|
497
409
|
- π **Better Errors** - Detailed messages with examples
|
|
498
410
|
- β
**No Breaking Changes** - Fully backward compatible
|
|
499
411
|
|
|
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
|
|
412
|
+
### v1.0.1 (2025-10-24)
|
|
507
413
|
|
|
508
|
-
|
|
414
|
+
- π **Documentation Updates** - Clarified inline SVG behavior
|
|
415
|
+
- π Added "How It Works" section
|
|
416
|
+
- π‘ Added "Why Inline SVG?" section explaining benefits
|
|
509
417
|
|
|
510
|
-
|
|
511
|
-
- Symbol IDs are now just filenames (e.g., `home` instead of `icon-home`)
|
|
418
|
+
### v1.0.0 (2025-10-23)
|
|
512
419
|
|
|
513
|
-
|
|
420
|
+
- π **Initial Release** - Production-ready Vite plugin
|
|
421
|
+
- π SVGO Optimization - 40-60% size reduction
|
|
422
|
+
- β‘ Hot Module Replacement - Instant updates
|
|
423
|
+
- π Security First - XSS protection and path traversal prevention
|
|
424
|
+
- πΎ Smart Caching - LRU-like cache with mtime validation
|
|
425
|
+
- π― Auto-Injection - Automatic sprite injection into HTML
|
|
426
|
+
- π¦ Zero Config - Works out of the box
|
|
427
|
+
- π³ Tree-Shakeable - ES modules with proper exports
|
|
514
428
|
|
|
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
|
-
```
|
|
429
|
+
For the complete changelog, see [CHANGELOG.md](CHANGELOG.md)
|
|
553
430
|
|
|
554
431
|
## π License
|
|
555
432
|
|
|
@@ -562,8 +439,8 @@ MIT Β© Karev G.S.
|
|
|
562
439
|
|
|
563
440
|
## π§ Support
|
|
564
441
|
|
|
565
|
-
- π [Issues](https://github.com/
|
|
566
|
-
- π¬ [Discussions](https://github.com/
|
|
442
|
+
- π [Issues](https://github.com/gkarev/vite-svg-sprite-generator-plugin/issues)
|
|
443
|
+
- π¬ [Discussions](https://github.com/gkarev/vite-svg-sprite-generator-plugin/discussions)
|
|
567
444
|
|
|
568
445
|
---
|
|
569
446
|
|
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.3",
|
|
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",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
|
-
"url": "https://github.com/gkarev/vite-svg-sprite-generator-plugin.git"
|
|
46
|
+
"url": "git+https://github.com/gkarev/vite-svg-sprite-generator-plugin.git"
|
|
47
47
|
},
|
|
48
48
|
"bugs": {
|
|
49
49
|
"url": "https://github.com/gkarev/vite-svg-sprite-generator-plugin/issues"
|
|
@@ -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: [
|