vite-svg-sprite-generator-plugin 1.1.4 → 1.1.6
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 +57 -1
- package/README.md +7 -0
- package/package.json +1 -1
- package/vite-svg-sprite-generator-plugin.js +29 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,16 +2,72 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.1.6] - 2025-01-28
|
|
6
|
+
|
|
7
|
+
### 🐛 Bug Fix - Preview Mode Detection
|
|
8
|
+
|
|
9
|
+
- **FIXED:** Preview mode detection now works correctly
|
|
10
|
+
- **ISSUE:** Plugin was showing validation messages during `vite preview`
|
|
11
|
+
- **ROOT CAUSE:** Vite runs preview as `command="serve"` + `mode="production"`
|
|
12
|
+
- **SOLUTION:** Added smart detection: `serve + production + !SSR = preview`
|
|
13
|
+
|
|
14
|
+
### 🔍 Changes
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
// Now correctly detects preview mode
|
|
18
|
+
isLikelyPreview =
|
|
19
|
+
isPreview ||
|
|
20
|
+
resolvedConfig.mode === 'preview' ||
|
|
21
|
+
(command === 'serve' && mode === 'production' && !build?.ssr);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### ✅ Result
|
|
25
|
+
|
|
26
|
+
- Preview mode now correctly skips validation ✅
|
|
27
|
+
- Preview mode skips sprite generation ✅
|
|
28
|
+
- Preview runs instantly (0ms) ✅
|
|
29
|
+
- Debug logging shows mode detection ✅
|
|
30
|
+
|
|
31
|
+
### 📊 Testing
|
|
32
|
+
|
|
33
|
+
**Before (v1.1.4):**
|
|
34
|
+
```
|
|
35
|
+
vite preview → "Validated icons folder" ❌
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**After (v1.1.6):**
|
|
39
|
+
```
|
|
40
|
+
vite preview → "Preview mode detected: skipping" ✅
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
5
45
|
## [1.1.4] - 2025-01-21
|
|
6
46
|
|
|
7
47
|
### ⚡ Performance - Smart Launch Mode
|
|
8
48
|
|
|
9
49
|
- **NEW:** Intelligent mode detection for preview command
|
|
10
|
-
- **IMPROVED:** Preview mode now skips unnecessary operations
|
|
50
|
+
- **IMPROVED:** Preview mode now skips unnecessary operations
|
|
11
51
|
- **ADDED:** Automatic command detection (serve/build/preview)
|
|
12
52
|
- **OPTIMIZED:** Preview runs instantly (0ms instead of 583ms)
|
|
13
53
|
- **NEW:** Skipping path validation in preview mode
|
|
14
54
|
- **NEW:** Skipping sprite generation in preview mode
|
|
55
|
+
- **ADDED:** Debug logging to understand Vite mode detection
|
|
56
|
+
- **IMPROVED:** Additional check for `resolvedConfig.mode === 'preview'`
|
|
57
|
+
|
|
58
|
+
### 🔍 Preview Mode Detection (Fixed)
|
|
59
|
+
|
|
60
|
+
**Issue:** The plugin was showing validation messages during `vite preview` because Vite runs preview as `command="serve"` + `mode="production"`.
|
|
61
|
+
|
|
62
|
+
**Fix:** Added smart detection logic:
|
|
63
|
+
- Detects `isPreview` flag
|
|
64
|
+
- Detects `mode === 'preview'`
|
|
65
|
+
- Detects `serve` + `production` combination (typical for preview)
|
|
66
|
+
- Excludes SSR builds from this check
|
|
67
|
+
|
|
68
|
+
Now the plugin correctly skips validation and sprite generation in preview mode.
|
|
69
|
+
|
|
70
|
+
Enable `verbose: true` to see debug information: `command`, `isPreview`, `mode`.
|
|
15
71
|
|
|
16
72
|
### 🎯 Optimization Details
|
|
17
73
|
|
package/README.md
CHANGED
|
@@ -394,6 +394,13 @@ sun.svg : 305 → 287 bytes (-5.9%)
|
|
|
394
394
|
|
|
395
395
|
## 📝 Changelog
|
|
396
396
|
|
|
397
|
+
### v1.1.6 (2025-01-28)
|
|
398
|
+
|
|
399
|
+
- 🐛 **Fixed Preview Detection** - Preview mode now correctly detected
|
|
400
|
+
- 🔍 **Smart Detection** - Detects `serve + production + !SSR = preview`
|
|
401
|
+
- ✅ **Confirmed Working** - Preview skips validation (0ms)
|
|
402
|
+
- 🎯 **Debug Logging** - Shows `command`, `isPreview`, `mode` when verbose
|
|
403
|
+
|
|
397
404
|
### v1.1.4 (2025-01-21)
|
|
398
405
|
|
|
399
406
|
- ⚡ **Smart Launch Mode** - Intelligent mode detection for preview command
|
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.6",
|
|
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",
|
|
@@ -8,9 +8,15 @@ import { normalizePath } from 'vite';
|
|
|
8
8
|
* Production-ready plugin for automatic SVG sprite generation
|
|
9
9
|
* with HMR support, SVGO optimization, and security features
|
|
10
10
|
*
|
|
11
|
-
* @version 1.1.
|
|
11
|
+
* @version 1.1.6
|
|
12
12
|
* @package vite-svg-sprite-generator-plugin
|
|
13
13
|
*
|
|
14
|
+
* @changelog v1.1.6
|
|
15
|
+
* - FIXED: Preview mode detection now works correctly
|
|
16
|
+
* - Preview detected as: serve + production + !SSR
|
|
17
|
+
* - Added debug logging for mode detection
|
|
18
|
+
* - Confirmed: Preview mode skips validation (0ms)
|
|
19
|
+
*
|
|
14
20
|
* @changelog v1.1.4
|
|
15
21
|
* - Intelligent mode detection for preview command
|
|
16
22
|
* - Preview mode skips unnecessary operations (0ms vs 583ms)
|
|
@@ -427,7 +433,9 @@ export default function svgSpritePlugin(userOptions = {}) {
|
|
|
427
433
|
// после получения viteRoot из конфигурации
|
|
428
434
|
let viteRoot = process.cwd(); // Дефолтное значение (будет перезаписано)
|
|
429
435
|
let validatedIconsFolder = ''; // Безопасный путь после валидации
|
|
430
|
-
let command = 'serve'; // Команда Vite (serve/build
|
|
436
|
+
let command = 'serve'; // Команда Vite (serve/build)
|
|
437
|
+
let isPreview = false; // Флаг preview режима
|
|
438
|
+
let isLikelyPreview = false; // Расширенная проверка preview режима
|
|
431
439
|
|
|
432
440
|
// ===== ИНКАПСУЛИРОВАННОЕ СОСТОЯНИЕ ПЛАГИНА =====
|
|
433
441
|
// Каждый экземпляр плагина имеет свое изолированное состояние
|
|
@@ -629,13 +637,28 @@ export default function svgSpritePlugin(userOptions = {}) {
|
|
|
629
637
|
// Получаем точный root из Vite конфигурации
|
|
630
638
|
viteRoot = resolvedConfig.root || process.cwd();
|
|
631
639
|
|
|
632
|
-
// Определяем команду
|
|
640
|
+
// Определяем команду и режим
|
|
633
641
|
command = resolvedConfig.command || 'serve';
|
|
642
|
+
isPreview = resolvedConfig.isPreview || false;
|
|
643
|
+
|
|
644
|
+
// Отладочная информация
|
|
645
|
+
if (options.verbose) {
|
|
646
|
+
logger.log(`🔍 Debug: command="${command}", isPreview=${isPreview}, mode="${resolvedConfig.mode}"`);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// Определение preview режима:
|
|
650
|
+
// vite preview запускается как command="serve" + mode="production"
|
|
651
|
+
// Проверяем все возможные варианты определения preview режима
|
|
652
|
+
isLikelyPreview =
|
|
653
|
+
isPreview ||
|
|
654
|
+
resolvedConfig.mode === 'preview' ||
|
|
655
|
+
// Preview часто определяется как serve + production без build
|
|
656
|
+
(command === 'serve' && resolvedConfig.mode === 'production' && !resolvedConfig.build?.ssr);
|
|
634
657
|
|
|
635
658
|
// В preview режиме НЕ валидируем пути (проект уже собран)
|
|
636
|
-
if (
|
|
659
|
+
if (isLikelyPreview) {
|
|
637
660
|
if (options.verbose) {
|
|
638
|
-
logger.log('🚀 Preview mode: skipping path validation');
|
|
661
|
+
logger.log('🚀 Preview mode detected: skipping path validation');
|
|
639
662
|
}
|
|
640
663
|
return;
|
|
641
664
|
}
|
|
@@ -658,7 +681,7 @@ export default function svgSpritePlugin(userOptions = {}) {
|
|
|
658
681
|
// Хук для начала сборки
|
|
659
682
|
async buildStart() {
|
|
660
683
|
// В preview режиме НЕ генерируем спрайт (уже собран в dist/)
|
|
661
|
-
if (
|
|
684
|
+
if (isLikelyPreview) {
|
|
662
685
|
if (options.verbose) {
|
|
663
686
|
logger.log('✅ Preview mode: using pre-built sprite from dist/');
|
|
664
687
|
}
|