vite-plugin-svg-spritegen 2.0.4 → 2.0.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/README.md CHANGED
@@ -66,3 +66,34 @@ export const IconBase: FC<SVGProps<SVGSVGElement> & { icon: IconName }> = ({ ico
66
66
  ```jsx
67
67
  <Icon icon="plus" />
68
68
  ```
69
+
70
+ ### Stripping Unused Icons
71
+
72
+ By default the plugin scans your source files during `build` and drops any icons that
73
+ aren't referenced, keeping the emitted `sprite.svg` small. Configure this via `stripUnused`:
74
+
75
+ ```typescript
76
+ svgSpritegen({
77
+ outputDir: 'src/assets/icons',
78
+ stripUnused: {
79
+ // Set false to include every source SVG in the sprite.
80
+ enabled: true,
81
+ // A RegExp (or string) with a named capture group `icon`. Every match is checked
82
+ // against the real icon set, so unrelated strings are ignored automatically.
83
+ matchPattern: /['"`](?<icon>[^'"`\r\n]+?)['"`]/g,
84
+ // Which files to scan / skip (node_modules is always excluded).
85
+ srcInclude: ['**/*.[jt]s?(x)', '**/*.[cm][jt]s', '**/*.md?(x)'],
86
+ srcExclude: [],
87
+ // Icon ids to always keep, even if they aren't detected in source.
88
+ whitelist: [],
89
+ },
90
+ });
91
+ ```
92
+
93
+ The default `matchPattern` treats **any quoted string** (`"star"`, `'star'`, or
94
+ `` `star` ``) as a possible icon reference. Because each candidate is validated against the
95
+ generated icon set before being kept, over-matching is harmless — this catches icon names
96
+ wherever they appear (component props, object/record values, ternaries, arrays) rather than
97
+ only `icon="..."` assignments. Provide your own `matchPattern` (with an `icon` named group)
98
+ to narrow this if needed, and use `whitelist` for icons chosen in ways static analysis can't
99
+ see (e.g. names built from runtime data).
package/dist/index.js CHANGED
@@ -187,7 +187,7 @@ var writeSprite = (spritePath, svgMap) => {
187
187
  };
188
188
  //#endregion
189
189
  //#region src/index.ts
190
- var defaultMatchPattern = /['"`]?icon['"`]?\s*[=:]{1}\s*['"`]{1}(?<icon>.+?)['"`]{1}/gi;
190
+ var defaultMatchPattern = /['"`](?<icon>[^'"`\r\n]+?)['"`]/g;
191
191
  var inputConfigDefaults = {
192
192
  pattern: "**/*.svg",
193
193
  baseDir: "./",
@@ -199,7 +199,11 @@ var inputConfigDefaults = {
199
199
  var stripUnusedDefaults = {
200
200
  enabled: true,
201
201
  matchPattern: defaultMatchPattern,
202
- srcInclude: ["**/*.[jt]sx", "**/*.md?(x)"],
202
+ srcInclude: [
203
+ "**/*.[jt]s?(x)",
204
+ "**/*.[cm][jt]s",
205
+ "**/*.md?(x)"
206
+ ],
203
207
  srcExclude: [],
204
208
  whitelist: []
205
209
  };
package/dist/index.mjs CHANGED
@@ -159,7 +159,7 @@ var writeSprite = (spritePath, svgMap) => {
159
159
  };
160
160
  //#endregion
161
161
  //#region src/index.ts
162
- var defaultMatchPattern = /['"`]?icon['"`]?\s*[=:]{1}\s*['"`]{1}(?<icon>.+?)['"`]{1}/gi;
162
+ var defaultMatchPattern = /['"`](?<icon>[^'"`\r\n]+?)['"`]/g;
163
163
  var inputConfigDefaults = {
164
164
  pattern: "**/*.svg",
165
165
  baseDir: "./",
@@ -171,7 +171,11 @@ var inputConfigDefaults = {
171
171
  var stripUnusedDefaults = {
172
172
  enabled: true,
173
173
  matchPattern: defaultMatchPattern,
174
- srcInclude: ["**/*.[jt]sx", "**/*.md?(x)"],
174
+ srcInclude: [
175
+ "**/*.[jt]s?(x)",
176
+ "**/*.[cm][jt]s",
177
+ "**/*.md?(x)"
178
+ ],
175
179
  srcExclude: [],
176
180
  whitelist: []
177
181
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-svg-spritegen",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Vite plugin that generates an svg spritesheet, optionally removing unused svg files.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",