@rsbuild/plugin-svgr 1.0.1-beta.2 → 1.0.1-beta.4
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/index.cjs +52 -16
- package/dist/index.d.ts +2 -2
- package/dist/index.js +53 -17
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -38,23 +38,58 @@ var import_node_path = __toESM(require("path"));
|
|
|
38
38
|
var import_plugin_react = require("@rsbuild/plugin-react");
|
|
39
39
|
var import_deepmerge = __toESM(require("deepmerge"));
|
|
40
40
|
var SVG_REGEX = /\.svg$/;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
removeViewBox: false
|
|
51
|
-
}
|
|
41
|
+
var getSvgoDefaultConfig = () => ({
|
|
42
|
+
plugins: [
|
|
43
|
+
{
|
|
44
|
+
name: "preset-default",
|
|
45
|
+
params: {
|
|
46
|
+
overrides: {
|
|
47
|
+
// viewBox is required to resize SVGs with CSS.
|
|
48
|
+
// @see https://github.com/svg/svgo/issues/1128
|
|
49
|
+
removeViewBox: false
|
|
52
50
|
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"prefixIds"
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
var dedupeSvgoPlugins = (config) => {
|
|
57
|
+
if (!config.plugins) {
|
|
58
|
+
return config;
|
|
59
|
+
}
|
|
60
|
+
let mergedPlugins = [];
|
|
61
|
+
for (const plugin of config.plugins) {
|
|
62
|
+
if (typeof plugin === "string") {
|
|
63
|
+
const exist = mergedPlugins.find(
|
|
64
|
+
(item) => item === plugin || typeof item === "object" && item.name === plugin
|
|
65
|
+
);
|
|
66
|
+
if (!exist) {
|
|
67
|
+
mergedPlugins.push(plugin);
|
|
68
|
+
}
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const strIndex = mergedPlugins.findIndex(
|
|
72
|
+
(item) => typeof item === "string" && item === plugin.name
|
|
73
|
+
);
|
|
74
|
+
if (strIndex !== -1) {
|
|
75
|
+
mergedPlugins[strIndex] = plugin;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
let isMerged = false;
|
|
79
|
+
mergedPlugins = mergedPlugins.map((item) => {
|
|
80
|
+
if (typeof item === "object" && item.name === plugin.name) {
|
|
81
|
+
isMerged = true;
|
|
82
|
+
return (0, import_deepmerge.default)(item, plugin);
|
|
83
|
+
}
|
|
84
|
+
return item;
|
|
85
|
+
});
|
|
86
|
+
if (!isMerged) {
|
|
87
|
+
mergedPlugins.push(plugin);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
config.plugins = mergedPlugins;
|
|
91
|
+
return config;
|
|
92
|
+
};
|
|
58
93
|
var PLUGIN_SVGR_NAME = "rsbuild:svgr";
|
|
59
94
|
var pluginSvgr = (options = {}) => ({
|
|
60
95
|
name: PLUGIN_SVGR_NAME,
|
|
@@ -77,6 +112,7 @@ var pluginSvgr = (options = {}) => ({
|
|
|
77
112
|
},
|
|
78
113
|
options.svgrOptions || {}
|
|
79
114
|
);
|
|
115
|
+
svgrOptions.svgoConfig = dedupeSvgoPlugins(svgrOptions.svgoConfig);
|
|
80
116
|
rule.oneOf(CHAIN_ID.ONE_OF.SVG_URL).type("asset/resource").resourceQuery(/(__inline=false|url)/).set("generator", generatorOptions);
|
|
81
117
|
rule.oneOf(CHAIN_ID.ONE_OF.SVG_INLINE).type("asset/inline").resourceQuery(/inline/);
|
|
82
118
|
rule.oneOf(CHAIN_ID.ONE_OF.SVG_REACT).type("javascript/auto").resourceQuery(options.query || /react/).use(CHAIN_ID.USE.SVGR).loader(import_node_path.default.resolve(__dirname, "./loader.cjs")).options({
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { RsbuildPlugin, Rspack } from '@rsbuild/core';
|
|
2
|
-
import type { Config } from '@svgr/core';
|
|
2
|
+
import type { Config as SvgrOptions } from '@svgr/core';
|
|
3
3
|
export type SvgDefaultExport = 'component' | 'url';
|
|
4
4
|
export type PluginSvgrOptions = {
|
|
5
5
|
/**
|
|
6
6
|
* Configure SVGR options.
|
|
7
7
|
* @see https://react-svgr.com/docs/options/
|
|
8
8
|
*/
|
|
9
|
-
svgrOptions?:
|
|
9
|
+
svgrOptions?: SvgrOptions;
|
|
10
10
|
/**
|
|
11
11
|
* Whether to allow the use of default import and named import at the same time.
|
|
12
12
|
* @default false
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire } from 'module';
|
|
|
2
2
|
var require = createRequire(import.meta['url']);
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
5
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.56.0_typescript@5.5.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
6
6
|
import { fileURLToPath } from "url";
|
|
7
7
|
import path from "path";
|
|
8
8
|
var getFilename = () => fileURLToPath(import.meta.url);
|
|
@@ -14,23 +14,58 @@ import path2 from "path";
|
|
|
14
14
|
import { PLUGIN_REACT_NAME } from "@rsbuild/plugin-react";
|
|
15
15
|
import deepmerge from "deepmerge";
|
|
16
16
|
var SVG_REGEX = /\.svg$/;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
removeViewBox: false
|
|
27
|
-
}
|
|
17
|
+
var getSvgoDefaultConfig = () => ({
|
|
18
|
+
plugins: [
|
|
19
|
+
{
|
|
20
|
+
name: "preset-default",
|
|
21
|
+
params: {
|
|
22
|
+
overrides: {
|
|
23
|
+
// viewBox is required to resize SVGs with CSS.
|
|
24
|
+
// @see https://github.com/svg/svgo/issues/1128
|
|
25
|
+
removeViewBox: false
|
|
28
26
|
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"prefixIds"
|
|
30
|
+
]
|
|
31
|
+
});
|
|
32
|
+
var dedupeSvgoPlugins = (config) => {
|
|
33
|
+
if (!config.plugins) {
|
|
34
|
+
return config;
|
|
35
|
+
}
|
|
36
|
+
let mergedPlugins = [];
|
|
37
|
+
for (const plugin of config.plugins) {
|
|
38
|
+
if (typeof plugin === "string") {
|
|
39
|
+
const exist = mergedPlugins.find(
|
|
40
|
+
(item) => item === plugin || typeof item === "object" && item.name === plugin
|
|
41
|
+
);
|
|
42
|
+
if (!exist) {
|
|
43
|
+
mergedPlugins.push(plugin);
|
|
44
|
+
}
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const strIndex = mergedPlugins.findIndex(
|
|
48
|
+
(item) => typeof item === "string" && item === plugin.name
|
|
49
|
+
);
|
|
50
|
+
if (strIndex !== -1) {
|
|
51
|
+
mergedPlugins[strIndex] = plugin;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
let isMerged = false;
|
|
55
|
+
mergedPlugins = mergedPlugins.map((item) => {
|
|
56
|
+
if (typeof item === "object" && item.name === plugin.name) {
|
|
57
|
+
isMerged = true;
|
|
58
|
+
return deepmerge(item, plugin);
|
|
59
|
+
}
|
|
60
|
+
return item;
|
|
61
|
+
});
|
|
62
|
+
if (!isMerged) {
|
|
63
|
+
mergedPlugins.push(plugin);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
config.plugins = mergedPlugins;
|
|
67
|
+
return config;
|
|
68
|
+
};
|
|
34
69
|
var PLUGIN_SVGR_NAME = "rsbuild:svgr";
|
|
35
70
|
var pluginSvgr = (options = {}) => ({
|
|
36
71
|
name: PLUGIN_SVGR_NAME,
|
|
@@ -53,6 +88,7 @@ var pluginSvgr = (options = {}) => ({
|
|
|
53
88
|
},
|
|
54
89
|
options.svgrOptions || {}
|
|
55
90
|
);
|
|
91
|
+
svgrOptions.svgoConfig = dedupeSvgoPlugins(svgrOptions.svgoConfig);
|
|
56
92
|
rule.oneOf(CHAIN_ID.ONE_OF.SVG_URL).type("asset/resource").resourceQuery(/(__inline=false|url)/).set("generator", generatorOptions);
|
|
57
93
|
rule.oneOf(CHAIN_ID.ONE_OF.SVG_INLINE).type("asset/inline").resourceQuery(/inline/);
|
|
58
94
|
rule.oneOf(CHAIN_ID.ONE_OF.SVG_REACT).type("javascript/auto").resourceQuery(options.query || /react/).use(CHAIN_ID.USE.SVGR).loader(path2.resolve(__dirname, "./loader.cjs")).options({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-svgr",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.4",
|
|
4
4
|
"description": "svgr plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,16 +28,17 @@
|
|
|
28
28
|
"@svgr/plugin-svgo": "8.1.0",
|
|
29
29
|
"deepmerge": "^4.3.1",
|
|
30
30
|
"loader-utils": "^2.0.4",
|
|
31
|
-
"@rsbuild/plugin-react": "1.0.1-beta.
|
|
31
|
+
"@rsbuild/plugin-react": "1.0.1-beta.4"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "18.x",
|
|
35
35
|
"file-loader": "6.2.0",
|
|
36
36
|
"prebundle": "1.2.2",
|
|
37
|
+
"svgo": "^3.3.2",
|
|
37
38
|
"typescript": "^5.5.2",
|
|
38
39
|
"url-loader": "4.1.1",
|
|
39
|
-
"@rsbuild/core": "1.0.1-beta.
|
|
40
|
-
"@scripts/test-helper": "1.0.1-beta.
|
|
40
|
+
"@rsbuild/core": "1.0.1-beta.4",
|
|
41
|
+
"@scripts/test-helper": "1.0.1-beta.4"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
44
|
"@rsbuild/core": "^1.0.1-beta.0"
|