vite-plugin-svg-spritegen 2.0.3 → 2.0.5
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 +31 -0
- package/dist/index.js +4 -2
- package/dist/index.mjs +4 -2
- package/package.json +1 -1
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]sx', '**/*.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
|
@@ -81,13 +81,15 @@ var writeIfChanged = (filePath, content) => {
|
|
|
81
81
|
var writeTypes = async (filePath, svgMap) => {
|
|
82
82
|
await writeIfChanged(filePath, [
|
|
83
83
|
"/* eslint-disable */",
|
|
84
|
+
"// biome-ignore-all format: autogenerated file — kept byte-stable across rebuilds",
|
|
85
|
+
"// biome-ignore-all lint: autogenerated file — kept byte-stable across rebuilds",
|
|
84
86
|
"",
|
|
85
87
|
"// This file is autogenerated. Keep it committed so typechecking works without a build.",
|
|
86
88
|
"",
|
|
87
89
|
"export type IconName = (typeof iconNames)[number];",
|
|
88
90
|
"",
|
|
89
91
|
"export const iconNames = [",
|
|
90
|
-
...[...svgMap.keys()].sort().map((name) =>
|
|
92
|
+
...[...svgMap.keys()].sort().map((name) => `\t'${name}',`),
|
|
91
93
|
"] as const;",
|
|
92
94
|
""
|
|
93
95
|
].join("\n"));
|
|
@@ -185,7 +187,7 @@ var writeSprite = (spritePath, svgMap) => {
|
|
|
185
187
|
};
|
|
186
188
|
//#endregion
|
|
187
189
|
//#region src/index.ts
|
|
188
|
-
var defaultMatchPattern = /['"`]
|
|
190
|
+
var defaultMatchPattern = /['"`](?<icon>[^'"`\r\n]+?)['"`]/g;
|
|
189
191
|
var inputConfigDefaults = {
|
|
190
192
|
pattern: "**/*.svg",
|
|
191
193
|
baseDir: "./",
|
package/dist/index.mjs
CHANGED
|
@@ -53,13 +53,15 @@ var writeIfChanged = (filePath, content) => {
|
|
|
53
53
|
var writeTypes = async (filePath, svgMap) => {
|
|
54
54
|
await writeIfChanged(filePath, [
|
|
55
55
|
"/* eslint-disable */",
|
|
56
|
+
"// biome-ignore-all format: autogenerated file — kept byte-stable across rebuilds",
|
|
57
|
+
"// biome-ignore-all lint: autogenerated file — kept byte-stable across rebuilds",
|
|
56
58
|
"",
|
|
57
59
|
"// This file is autogenerated. Keep it committed so typechecking works without a build.",
|
|
58
60
|
"",
|
|
59
61
|
"export type IconName = (typeof iconNames)[number];",
|
|
60
62
|
"",
|
|
61
63
|
"export const iconNames = [",
|
|
62
|
-
...[...svgMap.keys()].sort().map((name) =>
|
|
64
|
+
...[...svgMap.keys()].sort().map((name) => `\t'${name}',`),
|
|
63
65
|
"] as const;",
|
|
64
66
|
""
|
|
65
67
|
].join("\n"));
|
|
@@ -157,7 +159,7 @@ var writeSprite = (spritePath, svgMap) => {
|
|
|
157
159
|
};
|
|
158
160
|
//#endregion
|
|
159
161
|
//#region src/index.ts
|
|
160
|
-
var defaultMatchPattern = /['"`]
|
|
162
|
+
var defaultMatchPattern = /['"`](?<icon>[^'"`\r\n]+?)['"`]/g;
|
|
161
163
|
var inputConfigDefaults = {
|
|
162
164
|
pattern: "**/*.svg",
|
|
163
165
|
baseDir: "./",
|
package/package.json
CHANGED