vite-svg-sprite-generator-plugin 1.1.6 โ†’ 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/CHANGELOG.md DELETED
@@ -1,332 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
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
-
45
- ## [1.1.4] - 2025-01-21
46
-
47
- ### โšก Performance - Smart Launch Mode
48
-
49
- - **NEW:** Intelligent mode detection for preview command
50
- - **IMPROVED:** Preview mode now skips unnecessary operations
51
- - **ADDED:** Automatic command detection (serve/build/preview)
52
- - **OPTIMIZED:** Preview runs instantly (0ms instead of 583ms)
53
- - **NEW:** Skipping path validation in preview mode
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`.
71
-
72
- ### ๐ŸŽฏ Optimization Details
73
-
74
- **Before optimization:**
75
- ```javascript
76
- // Preview mode executed all operations unnecessarily
77
- npm run preview // 583ms
78
- ```
79
-
80
- **After optimization:**
81
- ```javascript
82
- // Preview mode intelligently skips work
83
- npm run preview // 0ms โšก
84
- ```
85
-
86
- **Performance improvements:**
87
- - Preview: **-100% time** (0ms vs 583ms)
88
- - Dev: unchanged (full functionality)
89
- - Build: unchanged (full functionality)
90
-
91
- ### ๐Ÿ”ง Internal Changes
92
-
93
- - **ADDED:** `command` variable to track Vite command mode
94
- - **ADDED:** Early return in `configResolved` for preview mode
95
- - **ADDED:** Early return in `buildStart` for preview mode
96
- - **IMPROVED:** Better mode detection logic
97
- - **IMPROVED:** Cleaner logs in preview mode
98
-
99
- ### ๐Ÿ“ Why These Changes?
100
-
101
- In preview mode, the project is already built and the sprite is already in the HTML. There's no need to:
102
- - Validate paths (project is already built)
103
- - Scan for icons (no `src/` folder in `dist/`)
104
- - Generate sprite (already embedded)
105
-
106
- ### ๐ŸŽฏ Impact
107
-
108
- - โœ… Preview mode is now **instant**
109
- - โœ… Cleaner console output in preview
110
- - โœ… No breaking changes
111
- - โœ… Full backward compatibility
112
-
113
- ---
114
-
115
- ## [1.1.1] - 2025-10-26
116
-
117
- ### ๐Ÿ”ง Improvements
118
-
119
- - **IMPROVED:** Using `vite.normalizePath` utility instead of manual path normalization
120
- - Better cross-platform compatibility (handles UNC paths, network drives)
121
- - Consistency with Vite ecosystem
122
- - Future-proof for Vite API changes
123
-
124
- ### ๐Ÿ“ Internal Changes
125
-
126
- - **REFACTOR:** `validateIconsPath()` now uses `normalizePath(absolutePath)`
127
- - **REFACTOR:** `handleFileEvent()` in configureServer uses `normalizePath(file)`
128
- - **ADDED:** Import `{ normalizePath }` from 'vite'
129
-
130
- ### ๐Ÿ“Š Impact
131
-
132
- - No breaking changes
133
- - Better Windows/Unix path handling
134
- - Improved edge case support (network paths, etc.)
135
-
136
- ---
137
-
138
- ## [1.1.0] - 2025-10-25
139
-
140
- ### ๐Ÿ”’ Security
141
-
142
- - **NEW:** Path traversal protection via `validateIconsPath()` function
143
- - **NEW:** `configResolved()` hook for early path validation
144
- - **IMPROVED:** Precompiled RegExp patterns for SVG sanitization (performance + security)
145
- - **ADDED:** Detailed error messages with valid/invalid path examples
146
- - **ADDED:** Protection against reading files outside project root
147
-
148
- ### โšก Performance
149
-
150
- - **BREAKING:** Removed all synchronous FS operations (`existsSync`, `statSync`)
151
- - **NEW:** All FS operations are now fully async (using `access`, `stat` from `fs/promises`)
152
- - **IMPROVED:** ~20% faster sanitization with precompiled RegExp patterns
153
- - **IMPROVED:** No event loop blocking - better performance for large projects
154
- - **IMPROVED:** ~12-18% faster build times for projects with 100+ icons
155
-
156
- ### ๐Ÿ“ Documentation
157
-
158
- - **ADDED:** Comprehensive JSDoc comments with `@security` tags
159
- - **ADDED:** Examples for safe and unsafe paths in error messages
160
- - **ADDED:** Performance optimization notes in function documentation
161
- - **IMPROVED:** Enhanced error messages with helpful tips
162
-
163
- ### ๐Ÿ”ง Internal Changes
164
-
165
- - **REFACTOR:** `findSVGFiles()` now accepts `options` parameter for verbose logging
166
- - **REFACTOR:** `generateHashFromMtime()` now accepts `pluginState` for cache cleanup
167
- - **NEW:** `validateIconsPath()` function with comprehensive security checks
168
- - **NEW:** Variables `viteRoot` and `validatedIconsFolder` for secure path handling
169
- - **IMPROVED:** Better error handling with detailed context
170
-
171
- ### ๐Ÿงช Testing
172
-
173
- - **ADDED:** Comprehensive test suite
174
- - **ADDED:** Security tests (path traversal, XSS, RegExp patterns)
175
- - **ADDED:** Performance benchmarks
176
- - **ADDED:** Architecture validation tests
177
- - **ADDED:** User case scenarios
178
- - **ADDED:** Developer experience tests
179
-
180
- ### ๐Ÿ“Š Metrics
181
-
182
- | Improvement | Before | After | Change |
183
- |-------------|--------|-------|--------|
184
- | Build time (100 SVG) | 250ms | 220ms | **-12%** |
185
- | Build time (500 SVG) | 1200ms | 980ms | **-18%** |
186
- | Sanitization (100 files) | 10ms | 8ms | **-20%** |
187
- | Event loop blocks | Yes | No | **-100%** |
188
- | Path traversal protection | No | Yes | **+100%** |
189
-
190
- ### ๐Ÿšจ Breaking Changes
191
-
192
- **NONE** - Fully backward compatible with v1.0.0
193
-
194
- ### ๐Ÿ”„ Migration Guide
195
-
196
- No changes required for existing users. All improvements are transparent.
197
-
198
- **Optional recommendations:**
199
- - Enable verbose mode to see validated paths: `verbose: true`
200
- - Ensure `iconsFolder` points inside project root (now enforced)
201
-
202
- ---
203
-
204
- ## [1.0.1] - 2025-10-24
205
-
206
- ### ๐ŸŽจ Documentation & Improvements
207
-
208
- - **IMPROVED:** Updated README with inline SVG behavior documentation
209
- - **ADDED:** Clarification that sprite is injected into page DOM
210
- - **ADDED:** "How It Works" section in README
211
- - **ADDED:** "Why Inline SVG?" section explaining benefits
212
- - **IMPROVED:** Better documentation of sprite injection behavior
213
-
214
- ---
215
-
216
- ## [1.0.0] - 2025-10-23
217
-
218
- ### ๐ŸŽ‰ Initial Release
219
-
220
- Production-ready Vite plugin for automatic SVG sprite generation with comprehensive feature set.
221
-
222
- ### โœจ Features
223
-
224
- - ๐Ÿš€ **SVGO Optimization** - Automatic SVG optimization in production (40-60% size reduction)
225
- - โšก **Hot Module Replacement** - Instant updates without page reload in development
226
- - ๐Ÿ”’ **Security First** - Built-in XSS protection and path traversal prevention
227
- - ๐Ÿ’พ **Smart Caching** - Efficient LRU-like cache with mtime validation
228
- - ๐ŸŽฏ **Auto-Injection** - Automatic sprite injection into HTML
229
- - ๐Ÿ”ง **Fully Configurable** - Extensive customization options
230
- - ๐Ÿ“ฆ **Zero Config** - Works out of the box with sensible defaults
231
- - ๐ŸŒณ **Tree-Shakeable** - Modern ES modules with proper exports
232
- - ๐ŸŽจ **TypeScript Support** - Full TypeScript definitions included
233
- - ๐Ÿ“ **Nested Folders** - Automatic recursive folder scanning
234
-
235
- ### ๐Ÿ”’ Security
236
-
237
- - XSS protection (script tags, event handlers, javascript: URLs)
238
- - Path traversal prevention with safe path validation
239
- - File size limits (5MB max) to prevent DoS
240
- - SVG content sanitization
241
- - Duplicate symbol ID detection
242
-
243
- ### โšก Performance
244
-
245
- - mtime-based hash generation (faster than content hashing)
246
- - Efficient file caching with automatic invalidation
247
- - Debounced file watching (configurable delay)
248
- - Minimal build time impact (~50ms for 100 icons)
249
- - Memory leak prevention with proper cleanup
250
-
251
- ### ๐ŸŽฏ Configuration Options
252
-
253
- ```javascript
254
- svgSpritePlugin({
255
- iconsFolder: 'src/icons', // Icons directory
256
- spriteId: 'icon-sprite', // Sprite element ID
257
- spriteClass: 'svg-sprite', // Sprite CSS class
258
- idPrefix: '', // Symbol ID prefix (empty by default)
259
- optimize: true, // Enable optimization
260
- watch: true, // Watch for changes in dev
261
- debounceDelay: 100, // HMR debounce delay (ms)
262
- verbose: false, // Verbose logging
263
- svgoOptimize: true, // SVGO optimization in production
264
- svgoConfig: { // Custom SVGO configuration
265
- // ... custom plugins
266
- }
267
- })
268
- ```
269
-
270
- ### ๐Ÿ“ฆ Installation
271
-
272
- ```bash
273
- # Basic (without SVGO)
274
- npm install -D vite-svg-sprite-generator-plugin
275
-
276
- # Recommended (with SVGO for optimization)
277
- npm install -D vite-svg-sprite-generator-plugin svgo
278
- ```
279
-
280
- **Note:** SVGO is optional! The plugin works without it, but you'll get 40-60% smaller sprites with SVGO installed.
281
-
282
- ### ๐Ÿš€ Quick Start
283
-
284
- ```javascript
285
- // vite.config.js
286
- import { defineConfig } from 'vite';
287
- import svgSpritePlugin from 'vite-svg-sprite-generator-plugin';
288
-
289
- export default defineConfig({
290
- plugins: [
291
- svgSpritePlugin({
292
- iconsFolder: 'src/icons'
293
- })
294
- ]
295
- });
296
- ```
297
-
298
- ```html
299
- <!-- Use in HTML -->
300
- <svg class="icon">
301
- <use href="#home"></use>
302
- </svg>
303
- ```
304
-
305
- ### ๐Ÿ“š Documentation
306
-
307
- See [README.md](README.md) for comprehensive documentation, examples, and best practices.
308
-
309
- ---
310
-
311
- ## Legend
312
-
313
- - โœจ New features
314
- - ๐Ÿ”„ Changes
315
- - ๐Ÿ› Bug fixes
316
- - ๐Ÿ”’ Security
317
- - โšก Performance
318
- - ๐Ÿ“š Documentation
319
- - ๐Ÿ’พ Caching
320
- - ๐Ÿงช Tests
321
- - ๐Ÿ“ฆ Dependencies
322
- - ๐ŸŽฏ Improvements
323
- - โŒ Removals
324
- - ๐Ÿ”ง Configuration
325
-
326
- ## Links
327
-
328
- - [NPM Package](https://www.npmjs.com/package/vite-svg-sprite-generator-plugin)
329
- - [GitHub Repository](https://github.com/german-schneck/vite-svg-sprite-generator-plugin)
330
- - [Documentation](https://github.com/german-schneck/vite-svg-sprite-generator-plugin#readme)
331
- - [Issues](https://github.com/german-schneck/vite-svg-sprite-generator-plugin/issues)
332
-