vite-plugin-svg-spritegen 1.2.8 → 1.4.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/dist/build-svg-map.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +26 -23
- package/dist/index.mjs +25 -22
- package/dist/types.d.ts +5 -2
- package/package.json +1 -1
package/dist/build-svg-map.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const buildSvgMap: (inputConfigs:
|
|
1
|
+
import type { InputConfigWithDefaults, SvgMap } from './types';
|
|
2
|
+
export declare const buildSvgMap: (inputConfigs: InputConfigWithDefaults[]) => Promise<SvgMap>;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
3
|
const path = require("node:path");
|
|
4
4
|
const node_crypto = require("node:crypto");
|
|
5
5
|
const chokidar = require("chokidar");
|
|
@@ -88,6 +88,26 @@ const writeSprite = (spritePath, svgMap) => {
|
|
|
88
88
|
if (spritePath === svg.filePath) continue;
|
|
89
89
|
let content2 = svg.content;
|
|
90
90
|
if (svg.svgo !== false) {
|
|
91
|
+
const svgoDefault = {
|
|
92
|
+
plugins: [
|
|
93
|
+
{
|
|
94
|
+
name: "preset-default",
|
|
95
|
+
params: {
|
|
96
|
+
overrides: {
|
|
97
|
+
removeViewBox: false,
|
|
98
|
+
convertColors: { currentColor: true },
|
|
99
|
+
...svg.svgoOverrides
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"removeDimensions",
|
|
104
|
+
{
|
|
105
|
+
name: "removeAttrs",
|
|
106
|
+
params: { attrs: "(stroke-width|stroke-linecap|stroke-linejoin|class)" }
|
|
107
|
+
}
|
|
108
|
+
]
|
|
109
|
+
};
|
|
110
|
+
svg.svgo = svg.svgo ?? svgoDefault;
|
|
91
111
|
content2 = svgo.optimize(content2, {
|
|
92
112
|
...svg.svgo,
|
|
93
113
|
plugins: [
|
|
@@ -132,37 +152,19 @@ const writeSprite = (spritePath, svgMap) => {
|
|
|
132
152
|
writeIfChanged(spritePath, content);
|
|
133
153
|
return content;
|
|
134
154
|
};
|
|
135
|
-
const
|
|
136
|
-
plugins: [
|
|
137
|
-
{
|
|
138
|
-
name: "preset-default",
|
|
139
|
-
params: {
|
|
140
|
-
overrides: {
|
|
141
|
-
removeViewBox: false,
|
|
142
|
-
convertColors: { currentColor: true }
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
"removeDimensions",
|
|
147
|
-
{
|
|
148
|
-
name: "removeAttrs",
|
|
149
|
-
params: { attrs: "(stroke-width|stroke-linecap|stroke-linejoin|class)" }
|
|
150
|
-
}
|
|
151
|
-
]
|
|
152
|
-
};
|
|
153
|
-
const defaultMatchPattern = /(?:(?:name)|(?:iconName)|(?:icon)): "(?<icon>.+?)"/g;
|
|
155
|
+
const defaultMatchPattern = /((name)|(iconName)|(icon)):\s?"(?<icon>.+?)"/g;
|
|
154
156
|
const inputConfigDefaults = {
|
|
155
157
|
pattern: "**/*.svg",
|
|
156
158
|
baseDir: "./",
|
|
157
159
|
prefix: "",
|
|
158
160
|
removeAttrs: [],
|
|
159
|
-
svgo: svgoDefault,
|
|
160
161
|
svgoPlugins: [],
|
|
161
162
|
getSymbolId: (config) => config.prefix + config.matchPath.replace(/\.[^/.]+$/, "").replaceAll("/", "-").toLowerCase()
|
|
162
163
|
};
|
|
163
164
|
const stripUnusedDefaults = {
|
|
164
165
|
enabled: true,
|
|
165
|
-
|
|
166
|
+
matchPattern: defaultMatchPattern,
|
|
167
|
+
srcInclude: ["**/*.[jt]sx", "**/*.md?(x)"],
|
|
166
168
|
srcExclude: [],
|
|
167
169
|
whitelist: []
|
|
168
170
|
};
|
|
@@ -227,7 +229,7 @@ function svgSpritegen(config) {
|
|
|
227
229
|
},
|
|
228
230
|
moduleParsed(info) {
|
|
229
231
|
if (!isBuild || !stripUnusedResolved.enabled || !srcFilter(info.id) || !info.code) return;
|
|
230
|
-
const matchPattern =
|
|
232
|
+
const matchPattern = new RegExp(stripUnusedResolved.matchPattern, "g");
|
|
231
233
|
const matches = [...info.code.matchAll(matchPattern)].flatMap(
|
|
232
234
|
({ groups }) => (groups == null ? void 0 : groups.icon) ?? []
|
|
233
235
|
);
|
|
@@ -272,4 +274,5 @@ function svgSpritegen(config) {
|
|
|
272
274
|
}
|
|
273
275
|
};
|
|
274
276
|
}
|
|
277
|
+
exports.default = svgSpritegen;
|
|
275
278
|
exports.svgSpritegen = svgSpritegen;
|
package/dist/index.mjs
CHANGED
|
@@ -86,6 +86,26 @@ const writeSprite = (spritePath, svgMap) => {
|
|
|
86
86
|
if (spritePath === svg.filePath) continue;
|
|
87
87
|
let content2 = svg.content;
|
|
88
88
|
if (svg.svgo !== false) {
|
|
89
|
+
const svgoDefault = {
|
|
90
|
+
plugins: [
|
|
91
|
+
{
|
|
92
|
+
name: "preset-default",
|
|
93
|
+
params: {
|
|
94
|
+
overrides: {
|
|
95
|
+
removeViewBox: false,
|
|
96
|
+
convertColors: { currentColor: true },
|
|
97
|
+
...svg.svgoOverrides
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"removeDimensions",
|
|
102
|
+
{
|
|
103
|
+
name: "removeAttrs",
|
|
104
|
+
params: { attrs: "(stroke-width|stroke-linecap|stroke-linejoin|class)" }
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
};
|
|
108
|
+
svg.svgo = svg.svgo ?? svgoDefault;
|
|
89
109
|
content2 = optimize(content2, {
|
|
90
110
|
...svg.svgo,
|
|
91
111
|
plugins: [
|
|
@@ -130,37 +150,19 @@ const writeSprite = (spritePath, svgMap) => {
|
|
|
130
150
|
writeIfChanged(spritePath, content);
|
|
131
151
|
return content;
|
|
132
152
|
};
|
|
133
|
-
const
|
|
134
|
-
plugins: [
|
|
135
|
-
{
|
|
136
|
-
name: "preset-default",
|
|
137
|
-
params: {
|
|
138
|
-
overrides: {
|
|
139
|
-
removeViewBox: false,
|
|
140
|
-
convertColors: { currentColor: true }
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
"removeDimensions",
|
|
145
|
-
{
|
|
146
|
-
name: "removeAttrs",
|
|
147
|
-
params: { attrs: "(stroke-width|stroke-linecap|stroke-linejoin|class)" }
|
|
148
|
-
}
|
|
149
|
-
]
|
|
150
|
-
};
|
|
151
|
-
const defaultMatchPattern = /(?:(?:name)|(?:iconName)|(?:icon)): "(?<icon>.+?)"/g;
|
|
153
|
+
const defaultMatchPattern = /((name)|(iconName)|(icon)):\s?"(?<icon>.+?)"/g;
|
|
152
154
|
const inputConfigDefaults = {
|
|
153
155
|
pattern: "**/*.svg",
|
|
154
156
|
baseDir: "./",
|
|
155
157
|
prefix: "",
|
|
156
158
|
removeAttrs: [],
|
|
157
|
-
svgo: svgoDefault,
|
|
158
159
|
svgoPlugins: [],
|
|
159
160
|
getSymbolId: (config) => config.prefix + config.matchPath.replace(/\.[^/.]+$/, "").replaceAll("/", "-").toLowerCase()
|
|
160
161
|
};
|
|
161
162
|
const stripUnusedDefaults = {
|
|
162
163
|
enabled: true,
|
|
163
|
-
|
|
164
|
+
matchPattern: defaultMatchPattern,
|
|
165
|
+
srcInclude: ["**/*.[jt]sx", "**/*.md?(x)"],
|
|
164
166
|
srcExclude: [],
|
|
165
167
|
whitelist: []
|
|
166
168
|
};
|
|
@@ -225,7 +227,7 @@ function svgSpritegen(config) {
|
|
|
225
227
|
},
|
|
226
228
|
moduleParsed(info) {
|
|
227
229
|
if (!isBuild || !stripUnusedResolved.enabled || !srcFilter(info.id) || !info.code) return;
|
|
228
|
-
const matchPattern =
|
|
230
|
+
const matchPattern = new RegExp(stripUnusedResolved.matchPattern, "g");
|
|
229
231
|
const matches = [...info.code.matchAll(matchPattern)].flatMap(
|
|
230
232
|
({ groups }) => (groups == null ? void 0 : groups.icon) ?? []
|
|
231
233
|
);
|
|
@@ -271,5 +273,6 @@ function svgSpritegen(config) {
|
|
|
271
273
|
};
|
|
272
274
|
}
|
|
273
275
|
export {
|
|
276
|
+
svgSpritegen as default,
|
|
274
277
|
svgSpritegen
|
|
275
278
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FilterPattern } from 'vite';
|
|
2
2
|
import { Config as SvgoConfig } from 'svgo';
|
|
3
|
+
import { PresetDefaultOverrides } from 'svgo/plugins/plugins-types';
|
|
3
4
|
export interface InputConfig {
|
|
4
5
|
pattern?: string;
|
|
5
6
|
baseDir?: string;
|
|
@@ -7,9 +8,11 @@ export interface InputConfig {
|
|
|
7
8
|
getSymbolId?: (config: Omit<ResolvedInputConfig, 'symbolId'>) => string;
|
|
8
9
|
removeAttrs?: string[];
|
|
9
10
|
svgoPlugins?: SvgoConfig['plugins'];
|
|
11
|
+
svgoOverrides?: PresetDefaultOverrides;
|
|
10
12
|
svgo?: SvgoConfig | false;
|
|
11
13
|
}
|
|
12
|
-
export
|
|
14
|
+
export type InputConfigWithDefaults = Required<Omit<InputConfig, 'svgoOverrides' | 'svgo'>> & Pick<InputConfig, 'svgoOverrides' | 'svgo'>;
|
|
15
|
+
export interface ResolvedInputConfig extends InputConfigWithDefaults {
|
|
13
16
|
symbolId: string;
|
|
14
17
|
matchPath: string;
|
|
15
18
|
filePath: string;
|
|
@@ -18,6 +21,7 @@ export interface ResolvedInputConfig extends Required<InputConfig> {
|
|
|
18
21
|
export type SvgMap = Map<string, ResolvedInputConfig>;
|
|
19
22
|
export interface StripUnusedConfig {
|
|
20
23
|
enabled?: boolean;
|
|
24
|
+
matchPattern?: string | RegExp;
|
|
21
25
|
srcInclude?: FilterPattern;
|
|
22
26
|
srcExclude?: FilterPattern;
|
|
23
27
|
whitelist?: string[];
|
|
@@ -29,5 +33,4 @@ export interface PluginConfig {
|
|
|
29
33
|
typesFileName?: string;
|
|
30
34
|
spriteFileName?: string;
|
|
31
35
|
gitignore?: boolean;
|
|
32
|
-
matchPattern?: string | RegExp;
|
|
33
36
|
}
|
package/package.json
CHANGED