vite-plugin-svg-spritegen 1.3.0 → 1.4.1

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.
@@ -1,2 +1,2 @@
1
- import type { InputConfig, SvgMap } from './types';
2
- export declare const buildSvgMap: (inputConfigs: Required<InputConfig>[]) => Promise<SvgMap>;
1
+ import type { InputConfigWithDefaults, SvgMap } from './types';
2
+ export declare const buildSvgMap: (inputConfigs: InputConfigWithDefaults[]) => Promise<SvgMap>;
package/dist/index.js CHANGED
@@ -88,6 +88,27 @@ 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
+ mergePaths: false,
99
+ convertColors: { currentColor: true },
100
+ ...svg.svgoOverrides
101
+ }
102
+ }
103
+ },
104
+ "removeDimensions",
105
+ {
106
+ name: "removeAttrs",
107
+ params: { attrs: "(stroke-width|stroke-linecap|stroke-linejoin|class)" }
108
+ }
109
+ ]
110
+ };
111
+ svg.svgo = svg.svgo ?? svgoDefault;
91
112
  content2 = svgo.optimize(content2, {
92
113
  ...svg.svgo,
93
114
  plugins: [
@@ -132,31 +153,12 @@ const writeSprite = (spritePath, svgMap) => {
132
153
  writeIfChanged(spritePath, content);
133
154
  return content;
134
155
  };
135
- const svgoDefault = {
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
156
  const defaultMatchPattern = /((name)|(iconName)|(icon)):\s?"(?<icon>.+?)"/g;
154
157
  const inputConfigDefaults = {
155
158
  pattern: "**/*.svg",
156
159
  baseDir: "./",
157
160
  prefix: "",
158
161
  removeAttrs: [],
159
- svgo: svgoDefault,
160
162
  svgoPlugins: [],
161
163
  getSymbolId: (config) => config.prefix + config.matchPath.replace(/\.[^/.]+$/, "").replaceAll("/", "-").toLowerCase()
162
164
  };
package/dist/index.mjs CHANGED
@@ -86,6 +86,27 @@ 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
+ mergePaths: false,
97
+ convertColors: { currentColor: true },
98
+ ...svg.svgoOverrides
99
+ }
100
+ }
101
+ },
102
+ "removeDimensions",
103
+ {
104
+ name: "removeAttrs",
105
+ params: { attrs: "(stroke-width|stroke-linecap|stroke-linejoin|class)" }
106
+ }
107
+ ]
108
+ };
109
+ svg.svgo = svg.svgo ?? svgoDefault;
89
110
  content2 = optimize(content2, {
90
111
  ...svg.svgo,
91
112
  plugins: [
@@ -130,31 +151,12 @@ const writeSprite = (spritePath, svgMap) => {
130
151
  writeIfChanged(spritePath, content);
131
152
  return content;
132
153
  };
133
- const svgoDefault = {
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
154
  const defaultMatchPattern = /((name)|(iconName)|(icon)):\s?"(?<icon>.+?)"/g;
152
155
  const inputConfigDefaults = {
153
156
  pattern: "**/*.svg",
154
157
  baseDir: "./",
155
158
  prefix: "",
156
159
  removeAttrs: [],
157
- svgo: svgoDefault,
158
160
  svgoPlugins: [],
159
161
  getSymbolId: (config) => config.prefix + config.matchPath.replace(/\.[^/.]+$/, "").replaceAll("/", "-").toLowerCase()
160
162
  };
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 interface ResolvedInputConfig extends Required<InputConfig> {
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-svg-spritegen",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
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",