vite-plugin-svg-spritegen 2.0.6 → 2.0.8
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 +8 -2
- package/dist/build-svg-map.d.ts +6 -1
- package/dist/index.js +23 -10
- package/dist/index.mjs +23 -10
- package/dist/write-sprite.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,8 +81,14 @@ svgSpritegen({
|
|
|
81
81
|
// A RegExp (or string) with a named capture group `icon`. Every match is checked
|
|
82
82
|
// against the real icon set, so unrelated strings are ignored automatically.
|
|
83
83
|
matchPattern: /['"`](?<icon>[^'"`\r\n]+?)['"`]/g,
|
|
84
|
-
// Which files to scan / skip (node_modules is always excluded).
|
|
85
|
-
|
|
84
|
+
// Which files to scan / skip (node_modules is always excluded). These are matched by
|
|
85
|
+
// rolldown's native glob engine, which supports `*`, `**`, and `[...]` character classes
|
|
86
|
+
// but NOT extglobs like `?(x)`, `@(a|b)`, `+(...)` — list each extension explicitly.
|
|
87
|
+
srcInclude: [
|
|
88
|
+
'**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx',
|
|
89
|
+
'**/*.mjs', '**/*.cjs', '**/*.mts', '**/*.cts',
|
|
90
|
+
'**/*.md', '**/*.mdx',
|
|
91
|
+
],
|
|
86
92
|
srcExclude: [],
|
|
87
93
|
// Icon ids to always keep, even if they aren't detected in source.
|
|
88
94
|
whitelist: [],
|
package/dist/build-svg-map.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import type { InputConfigWithDefaults, SvgMap } from './types';
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Every input SVG by symbol id. `spritePath` is left out: when an input's `baseDir` is also the output directory, the
|
|
4
|
+
* generated sprite matches the input pattern too, and would otherwise turn up as an icon (in the types as well as the
|
|
5
|
+
* sprite) whenever it already exists from an earlier run.
|
|
6
|
+
*/
|
|
7
|
+
export declare const buildSvgMap: (inputConfigs: InputConfigWithDefaults[], spritePath?: string) => Promise<SvgMap>;
|
package/dist/index.js
CHANGED
|
@@ -34,13 +34,20 @@ fast_glob = __toESM(fast_glob);
|
|
|
34
34
|
let node_html_parser = require("node-html-parser");
|
|
35
35
|
let svgo = require("svgo");
|
|
36
36
|
//#region src/build-svg-map.ts
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Every input SVG by symbol id. `spritePath` is left out: when an input's `baseDir` is also the output directory, the
|
|
39
|
+
* generated sprite matches the input pattern too, and would otherwise turn up as an icon (in the types as well as the
|
|
40
|
+
* sprite) whenever it already exists from an earlier run.
|
|
41
|
+
*/
|
|
42
|
+
var buildSvgMap = async (inputConfigs, spritePath) => {
|
|
38
43
|
const svgMap = /* @__PURE__ */ new Map();
|
|
44
|
+
const excluded = spritePath && node_path.default.resolve(spritePath);
|
|
39
45
|
await Promise.all(inputConfigs.map(async (inputConfig) => {
|
|
40
46
|
const { pattern, baseDir, getSymbolId } = inputConfig;
|
|
41
47
|
const matchedPaths = await (0, fast_glob.default)(pattern, { cwd: baseDir });
|
|
42
48
|
await Promise.all(matchedPaths.map(async (matchPath) => {
|
|
43
49
|
const filePath = node_path.default.join(baseDir, matchPath);
|
|
50
|
+
if (node_path.default.resolve(filePath) === excluded) return;
|
|
44
51
|
const content = await node_fs.promises.readFile(filePath, "utf8");
|
|
45
52
|
const resolvedInputConfig = {
|
|
46
53
|
...inputConfig,
|
|
@@ -125,12 +132,11 @@ var writeGitignore = async (filePath, spriteName) => {
|
|
|
125
132
|
};
|
|
126
133
|
//#endregion
|
|
127
134
|
//#region src/write-sprite.ts
|
|
128
|
-
var buildSpriteContent = (svgMap
|
|
135
|
+
var buildSpriteContent = (svgMap) => {
|
|
129
136
|
const symbols = [];
|
|
130
137
|
const definitions = [];
|
|
131
138
|
const svgSorted = [...svgMap].sort((a, b) => String(a[0]).localeCompare(b[0])).map(([_, svg]) => svg);
|
|
132
139
|
for (const svg of svgSorted) {
|
|
133
|
-
if (spritePath && spritePath === svg.filePath) continue;
|
|
134
140
|
let content = svg.content;
|
|
135
141
|
if (svg.svgo !== false) {
|
|
136
142
|
const svgoDefault = { plugins: [
|
|
@@ -181,7 +187,7 @@ var buildSpriteContent = (svgMap, spritePath) => {
|
|
|
181
187
|
return lines.join("\n");
|
|
182
188
|
};
|
|
183
189
|
var writeSprite = (spritePath, svgMap) => {
|
|
184
|
-
const content = buildSpriteContent(svgMap
|
|
190
|
+
const content = buildSpriteContent(svgMap);
|
|
185
191
|
writeIfChanged(spritePath, content);
|
|
186
192
|
return content;
|
|
187
193
|
};
|
|
@@ -200,9 +206,16 @@ var stripUnusedDefaults = {
|
|
|
200
206
|
enabled: true,
|
|
201
207
|
matchPattern: defaultMatchPattern,
|
|
202
208
|
srcInclude: [
|
|
203
|
-
"**/*.
|
|
204
|
-
"**/*.
|
|
205
|
-
"**/*.
|
|
209
|
+
"**/*.js",
|
|
210
|
+
"**/*.jsx",
|
|
211
|
+
"**/*.ts",
|
|
212
|
+
"**/*.tsx",
|
|
213
|
+
"**/*.mjs",
|
|
214
|
+
"**/*.cjs",
|
|
215
|
+
"**/*.mts",
|
|
216
|
+
"**/*.cts",
|
|
217
|
+
"**/*.md",
|
|
218
|
+
"**/*.mdx"
|
|
206
219
|
],
|
|
207
220
|
srcExclude: [],
|
|
208
221
|
whitelist: []
|
|
@@ -244,7 +257,7 @@ function svgSpritegen(config) {
|
|
|
244
257
|
viteBase = config.base ?? "/";
|
|
245
258
|
},
|
|
246
259
|
async buildStart() {
|
|
247
|
-
allSvgs = await buildSvgMap(inputConfigsResolved);
|
|
260
|
+
allSvgs = await buildSvgMap(inputConfigsResolved, spriteFilePath);
|
|
248
261
|
await writeTypes(typesFilePath, allSvgs);
|
|
249
262
|
if (config.gitignore !== false) await writeGitignore(gitignoreFilePath, spriteNameResolved);
|
|
250
263
|
if (isBuild) {
|
|
@@ -254,7 +267,7 @@ function svgSpritegen(config) {
|
|
|
254
267
|
writeSprite(spriteFilePath, allSvgs);
|
|
255
268
|
const onWatch = (changedPath) => {
|
|
256
269
|
if (changedPath === spriteFilePath) return;
|
|
257
|
-
buildSvgMap(inputConfigsResolved).then((newAllSvgFiles) => {
|
|
270
|
+
buildSvgMap(inputConfigsResolved, spriteFilePath).then((newAllSvgFiles) => {
|
|
258
271
|
writeSprite(spriteFilePath, newAllSvgFiles);
|
|
259
272
|
});
|
|
260
273
|
};
|
|
@@ -304,7 +317,7 @@ function svgSpritegen(config) {
|
|
|
304
317
|
spriteRefId = this.emitFile({
|
|
305
318
|
type: "asset",
|
|
306
319
|
name: spriteNameResolved,
|
|
307
|
-
source: buildSpriteContent(sourceMap
|
|
320
|
+
source: buildSpriteContent(sourceMap)
|
|
308
321
|
});
|
|
309
322
|
},
|
|
310
323
|
renderChunk: {
|
package/dist/index.mjs
CHANGED
|
@@ -6,13 +6,20 @@ import fastGlob from "fast-glob";
|
|
|
6
6
|
import { parse } from "node-html-parser";
|
|
7
7
|
import { optimize } from "svgo";
|
|
8
8
|
//#region src/build-svg-map.ts
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Every input SVG by symbol id. `spritePath` is left out: when an input's `baseDir` is also the output directory, the
|
|
11
|
+
* generated sprite matches the input pattern too, and would otherwise turn up as an icon (in the types as well as the
|
|
12
|
+
* sprite) whenever it already exists from an earlier run.
|
|
13
|
+
*/
|
|
14
|
+
var buildSvgMap = async (inputConfigs, spritePath) => {
|
|
10
15
|
const svgMap = /* @__PURE__ */ new Map();
|
|
16
|
+
const excluded = spritePath && path.resolve(spritePath);
|
|
11
17
|
await Promise.all(inputConfigs.map(async (inputConfig) => {
|
|
12
18
|
const { pattern, baseDir, getSymbolId } = inputConfig;
|
|
13
19
|
const matchedPaths = await fastGlob(pattern, { cwd: baseDir });
|
|
14
20
|
await Promise.all(matchedPaths.map(async (matchPath) => {
|
|
15
21
|
const filePath = path.join(baseDir, matchPath);
|
|
22
|
+
if (path.resolve(filePath) === excluded) return;
|
|
16
23
|
const content = await promises.readFile(filePath, "utf8");
|
|
17
24
|
const resolvedInputConfig = {
|
|
18
25
|
...inputConfig,
|
|
@@ -97,12 +104,11 @@ var writeGitignore = async (filePath, spriteName) => {
|
|
|
97
104
|
};
|
|
98
105
|
//#endregion
|
|
99
106
|
//#region src/write-sprite.ts
|
|
100
|
-
var buildSpriteContent = (svgMap
|
|
107
|
+
var buildSpriteContent = (svgMap) => {
|
|
101
108
|
const symbols = [];
|
|
102
109
|
const definitions = [];
|
|
103
110
|
const svgSorted = [...svgMap].sort((a, b) => String(a[0]).localeCompare(b[0])).map(([_, svg]) => svg);
|
|
104
111
|
for (const svg of svgSorted) {
|
|
105
|
-
if (spritePath && spritePath === svg.filePath) continue;
|
|
106
112
|
let content = svg.content;
|
|
107
113
|
if (svg.svgo !== false) {
|
|
108
114
|
const svgoDefault = { plugins: [
|
|
@@ -153,7 +159,7 @@ var buildSpriteContent = (svgMap, spritePath) => {
|
|
|
153
159
|
return lines.join("\n");
|
|
154
160
|
};
|
|
155
161
|
var writeSprite = (spritePath, svgMap) => {
|
|
156
|
-
const content = buildSpriteContent(svgMap
|
|
162
|
+
const content = buildSpriteContent(svgMap);
|
|
157
163
|
writeIfChanged(spritePath, content);
|
|
158
164
|
return content;
|
|
159
165
|
};
|
|
@@ -172,9 +178,16 @@ var stripUnusedDefaults = {
|
|
|
172
178
|
enabled: true,
|
|
173
179
|
matchPattern: defaultMatchPattern,
|
|
174
180
|
srcInclude: [
|
|
175
|
-
"**/*.
|
|
176
|
-
"**/*.
|
|
177
|
-
"**/*.
|
|
181
|
+
"**/*.js",
|
|
182
|
+
"**/*.jsx",
|
|
183
|
+
"**/*.ts",
|
|
184
|
+
"**/*.tsx",
|
|
185
|
+
"**/*.mjs",
|
|
186
|
+
"**/*.cjs",
|
|
187
|
+
"**/*.mts",
|
|
188
|
+
"**/*.cts",
|
|
189
|
+
"**/*.md",
|
|
190
|
+
"**/*.mdx"
|
|
178
191
|
],
|
|
179
192
|
srcExclude: [],
|
|
180
193
|
whitelist: []
|
|
@@ -216,7 +229,7 @@ function svgSpritegen(config) {
|
|
|
216
229
|
viteBase = config.base ?? "/";
|
|
217
230
|
},
|
|
218
231
|
async buildStart() {
|
|
219
|
-
allSvgs = await buildSvgMap(inputConfigsResolved);
|
|
232
|
+
allSvgs = await buildSvgMap(inputConfigsResolved, spriteFilePath);
|
|
220
233
|
await writeTypes(typesFilePath, allSvgs);
|
|
221
234
|
if (config.gitignore !== false) await writeGitignore(gitignoreFilePath, spriteNameResolved);
|
|
222
235
|
if (isBuild) {
|
|
@@ -226,7 +239,7 @@ function svgSpritegen(config) {
|
|
|
226
239
|
writeSprite(spriteFilePath, allSvgs);
|
|
227
240
|
const onWatch = (changedPath) => {
|
|
228
241
|
if (changedPath === spriteFilePath) return;
|
|
229
|
-
buildSvgMap(inputConfigsResolved).then((newAllSvgFiles) => {
|
|
242
|
+
buildSvgMap(inputConfigsResolved, spriteFilePath).then((newAllSvgFiles) => {
|
|
230
243
|
writeSprite(spriteFilePath, newAllSvgFiles);
|
|
231
244
|
});
|
|
232
245
|
};
|
|
@@ -276,7 +289,7 @@ function svgSpritegen(config) {
|
|
|
276
289
|
spriteRefId = this.emitFile({
|
|
277
290
|
type: "asset",
|
|
278
291
|
name: spriteNameResolved,
|
|
279
|
-
source: buildSpriteContent(sourceMap
|
|
292
|
+
source: buildSpriteContent(sourceMap)
|
|
280
293
|
});
|
|
281
294
|
},
|
|
282
295
|
renderChunk: {
|
package/dist/write-sprite.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { SvgMap } from './types';
|
|
2
|
-
export declare const buildSpriteContent: (svgMap: SvgMap
|
|
2
|
+
export declare const buildSpriteContent: (svgMap: SvgMap) => string;
|
|
3
3
|
export declare const writeSprite: (spritePath: string, svgMap: SvgMap) => string;
|
package/package.json
CHANGED