@rsbuild/plugin-svgr 1.2.0 → 1.2.2
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 +1 -1
- package/compiled/file-loader/index.js +6 -6
- package/compiled/url-loader/index.js +6 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +40 -40
- package/dist/loader.mjs +13 -19
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ An Rsbuild plugin to use SVGR to transform SVG to React components via SVGR.
|
|
|
12
12
|
|
|
13
13
|
## Documentation
|
|
14
14
|
|
|
15
|
-
See [Documentation](https://rsbuild.
|
|
15
|
+
See [Documentation](https://rsbuild.rs/plugins/list/plugin-svgr).
|
|
16
16
|
|
|
17
17
|
## License
|
|
18
18
|
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
(() => {
|
|
2
2
|
"use strict";
|
|
3
3
|
var __webpack_modules__ = {
|
|
4
|
-
|
|
5
|
-
const loader = __nccwpck_require__(
|
|
4
|
+
389: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
5
|
+
const loader = __nccwpck_require__(727);
|
|
6
6
|
module.exports = loader.default;
|
|
7
7
|
module.exports.raw = loader.raw;
|
|
8
8
|
},
|
|
9
|
-
|
|
9
|
+
727: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports["default"] = loader;
|
|
12
12
|
exports.raw = void 0;
|
|
13
13
|
var _path = _interopRequireDefault(__nccwpck_require__(928));
|
|
14
14
|
var _loaderUtils = __nccwpck_require__(328);
|
|
15
|
-
var _utils = __nccwpck_require__(
|
|
15
|
+
var _utils = __nccwpck_require__(394);
|
|
16
16
|
function _interopRequireDefault(obj) {
|
|
17
17
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
18
18
|
}
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
const raw = true;
|
|
74
74
|
exports.raw = raw;
|
|
75
75
|
},
|
|
76
|
-
|
|
76
|
+
394: (__unused_webpack_module, exports) => {
|
|
77
77
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
78
|
exports.normalizePath = normalizePath;
|
|
79
79
|
function normalizePath(path, stripTrailing) {
|
|
@@ -128,6 +128,6 @@
|
|
|
128
128
|
}
|
|
129
129
|
if (typeof __nccwpck_require__ !== "undefined")
|
|
130
130
|
__nccwpck_require__.ab = __dirname + "/";
|
|
131
|
-
var __webpack_exports__ = __nccwpck_require__(
|
|
131
|
+
var __webpack_exports__ = __nccwpck_require__(389);
|
|
132
132
|
module.exports = __webpack_exports__;
|
|
133
133
|
})();
|
|
@@ -107,20 +107,20 @@
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
|
-
|
|
110
|
+
367: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
111
111
|
"use strict";
|
|
112
|
-
const loader = __nccwpck_require__(
|
|
112
|
+
const loader = __nccwpck_require__(345);
|
|
113
113
|
module.exports = loader.default;
|
|
114
114
|
module.exports.raw = loader.raw;
|
|
115
115
|
},
|
|
116
|
-
|
|
116
|
+
345: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
117
117
|
"use strict";
|
|
118
118
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
119
119
|
exports["default"] = loader;
|
|
120
120
|
exports.raw = void 0;
|
|
121
121
|
var _path = _interopRequireDefault(__nccwpck_require__(928));
|
|
122
122
|
var _mimeTypes = _interopRequireDefault(__nccwpck_require__(437));
|
|
123
|
-
var _normalizeFallback = _interopRequireDefault(__nccwpck_require__(
|
|
123
|
+
var _normalizeFallback = _interopRequireDefault(__nccwpck_require__(562));
|
|
124
124
|
function _interopRequireDefault(obj) {
|
|
125
125
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
126
126
|
}
|
|
@@ -212,7 +212,7 @@
|
|
|
212
212
|
const raw = true;
|
|
213
213
|
exports.raw = raw;
|
|
214
214
|
},
|
|
215
|
-
|
|
215
|
+
562: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
216
216
|
"use strict";
|
|
217
217
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
218
218
|
exports["default"] = normalizeFallback;
|
|
@@ -276,6 +276,6 @@
|
|
|
276
276
|
}
|
|
277
277
|
if (typeof __nccwpck_require__ !== "undefined")
|
|
278
278
|
__nccwpck_require__.ab = __dirname + "/";
|
|
279
|
-
var __webpack_exports__ = __nccwpck_require__(
|
|
279
|
+
var __webpack_exports__ = __nccwpck_require__(367);
|
|
280
280
|
module.exports = __webpack_exports__;
|
|
281
281
|
})();
|
package/dist/index.cjs
CHANGED
|
@@ -69,7 +69,7 @@ let src_dirname = external_node_path_default().dirname((0, external_node_url_nam
|
|
|
69
69
|
svgo: !0,
|
|
70
70
|
svgoConfig: getSvgoDefaultConfig()
|
|
71
71
|
}, options.svgrOptions || {});
|
|
72
|
-
svgrOptions.svgoConfig = dedupeSvgoPlugins(svgrOptions.svgoConfig), rule.oneOf(CHAIN_ID.ONE_OF.SVG_URL).type('asset/resource').resourceQuery(
|
|
72
|
+
svgrOptions.svgoConfig = dedupeSvgoPlugins(svgrOptions.svgoConfig), rule.oneOf(CHAIN_ID.ONE_OF.SVG_URL).type('asset/resource').resourceQuery(/^\?(__inline=false|url)$/).set('generator', generatorOptions), rule.oneOf(CHAIN_ID.ONE_OF.SVG_INLINE).type('asset/inline').resourceQuery(/^\?inline$/), CHAIN_ID.ONE_OF.SVG_RAW && rule.oneOf(CHAIN_ID.ONE_OF.SVG_RAW).type('asset/source').resourceQuery(/^\?raw$/), rule.oneOf(CHAIN_ID.ONE_OF.SVG_REACT).type("javascript/auto").resourceQuery(options.query || /react/).use(CHAIN_ID.USE.SVGR).loader(external_node_path_default().resolve(src_dirname, './loader.mjs')).options({
|
|
73
73
|
...svgrOptions,
|
|
74
74
|
exportType: 'default'
|
|
75
75
|
}).end();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { RsbuildPlugin, Rspack } from '@rsbuild/core';
|
|
2
|
-
import type { Config as
|
|
2
|
+
import type { Config as BaseSvgrOptions } from '@svgr/core';
|
|
3
|
+
import type { Config as SvgoConfig } from 'svgo';
|
|
4
|
+
type SvgrOptions = Omit<BaseSvgrOptions, 'svgoConfig'> & {
|
|
5
|
+
svgoConfig?: SvgoConfig;
|
|
6
|
+
};
|
|
3
7
|
export type SvgDefaultExport = 'component' | 'url';
|
|
4
8
|
export type PluginSvgrOptions = {
|
|
5
9
|
/**
|
|
@@ -28,3 +32,4 @@ export type PluginSvgrOptions = {
|
|
|
28
32
|
};
|
|
29
33
|
export declare const PLUGIN_SVGR_NAME = "rsbuild:svgr";
|
|
30
34
|
export declare const pluginSvgr: (options?: PluginSvgrOptions) => RsbuildPlugin;
|
|
35
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
let src_dirname =
|
|
6
|
-
plugins: [
|
|
7
|
-
{
|
|
8
|
-
name: 'preset-default',
|
|
9
|
-
params: {
|
|
10
|
-
overrides: {
|
|
11
|
-
removeViewBox: !1
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
'prefixIds'
|
|
16
|
-
]
|
|
17
|
-
}), dedupeSvgoPlugins = (config)=>{
|
|
18
|
-
if (!config.plugins) return config;
|
|
19
|
-
let mergedPlugins = [];
|
|
20
|
-
for (let plugin of config.plugins){
|
|
21
|
-
if ('string' == typeof plugin) {
|
|
22
|
-
mergedPlugins.find((item)=>item === plugin || 'object' == typeof item && item.name === plugin) || mergedPlugins.push(plugin);
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
let strIndex = mergedPlugins.findIndex((item)=>'string' == typeof item && item === plugin.name);
|
|
26
|
-
if (-1 !== strIndex) {
|
|
27
|
-
mergedPlugins[strIndex] = plugin;
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
let isMerged = !1;
|
|
31
|
-
mergedPlugins = mergedPlugins.map((item)=>'object' == typeof item && item.name === plugin.name ? (isMerged = !0, (0, __WEBPACK_EXTERNAL_MODULE_deepmerge__.default)(item, plugin)) : item), isMerged || mergedPlugins.push(plugin);
|
|
32
|
-
}
|
|
33
|
-
return config.plugins = mergedPlugins, config;
|
|
34
|
-
}, PLUGIN_SVGR_NAME = 'rsbuild:svgr', pluginSvgr = (options = {})=>({
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { PLUGIN_REACT_NAME } from "@rsbuild/plugin-react";
|
|
4
|
+
import deepmerge from "deepmerge";
|
|
5
|
+
let src_dirname = node_path.dirname(fileURLToPath(import.meta.url)), SVG_REGEX = /\.svg$/, PLUGIN_SVGR_NAME = 'rsbuild:svgr', pluginSvgr = (options = {})=>({
|
|
35
6
|
name: PLUGIN_SVGR_NAME,
|
|
36
7
|
pre: [
|
|
37
|
-
|
|
8
|
+
PLUGIN_REACT_NAME
|
|
38
9
|
],
|
|
39
10
|
setup (api) {
|
|
40
11
|
api.modifyBundlerChain(async (chain, { CHAIN_ID, environment })=>{
|
|
41
12
|
let { config } = environment, { dataUriLimit } = config.output, maxSize = 'number' == typeof dataUriLimit ? dataUriLimit : dataUriLimit.svg, generatorOptions = {};
|
|
42
13
|
chain.module.rules.has(CHAIN_ID.RULE.SVG) && (generatorOptions = chain.module.rules.get(CHAIN_ID.RULE.SVG).oneOfs.get(CHAIN_ID.ONE_OF.SVG_URL).get('generator'), chain.module.rules.delete(CHAIN_ID.RULE.SVG));
|
|
43
|
-
let rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(SVG_REGEX), svgrOptions = (
|
|
14
|
+
let rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(SVG_REGEX), svgrOptions = deepmerge({
|
|
44
15
|
svgo: !0,
|
|
45
|
-
svgoConfig:
|
|
16
|
+
svgoConfig: {
|
|
17
|
+
plugins: [
|
|
18
|
+
{
|
|
19
|
+
name: 'preset-default',
|
|
20
|
+
params: {
|
|
21
|
+
overrides: {
|
|
22
|
+
removeViewBox: !1
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
'prefixIds'
|
|
27
|
+
]
|
|
28
|
+
}
|
|
46
29
|
}, options.svgrOptions || {});
|
|
47
|
-
svgrOptions.svgoConfig =
|
|
30
|
+
svgrOptions.svgoConfig = ((config)=>{
|
|
31
|
+
if (!config.plugins) return config;
|
|
32
|
+
let mergedPlugins = [];
|
|
33
|
+
for (let plugin of config.plugins){
|
|
34
|
+
if ('string' == typeof plugin) {
|
|
35
|
+
mergedPlugins.find((item)=>item === plugin || 'object' == typeof item && item.name === plugin) || mergedPlugins.push(plugin);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
let strIndex = mergedPlugins.findIndex((item)=>'string' == typeof item && item === plugin.name);
|
|
39
|
+
if (-1 !== strIndex) {
|
|
40
|
+
mergedPlugins[strIndex] = plugin;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
let isMerged = !1;
|
|
44
|
+
mergedPlugins = mergedPlugins.map((item)=>'object' == typeof item && item.name === plugin.name ? (isMerged = !0, deepmerge(item, plugin)) : item), isMerged || mergedPlugins.push(plugin);
|
|
45
|
+
}
|
|
46
|
+
return config.plugins = mergedPlugins, config;
|
|
47
|
+
})(svgrOptions.svgoConfig), rule.oneOf(CHAIN_ID.ONE_OF.SVG_URL).type('asset/resource').resourceQuery(/^\?(__inline=false|url)$/).set('generator', generatorOptions), rule.oneOf(CHAIN_ID.ONE_OF.SVG_INLINE).type('asset/inline').resourceQuery(/^\?inline$/), CHAIN_ID.ONE_OF.SVG_RAW && rule.oneOf(CHAIN_ID.ONE_OF.SVG_RAW).type('asset/source').resourceQuery(/^\?raw$/), rule.oneOf(CHAIN_ID.ONE_OF.SVG_REACT).type("javascript/auto").resourceQuery(options.query || /react/).use(CHAIN_ID.USE.SVGR).loader(node_path.resolve(src_dirname, './loader.mjs')).options({
|
|
48
48
|
...svgrOptions,
|
|
49
49
|
exportType: 'default'
|
|
50
50
|
}).end();
|
|
@@ -61,10 +61,10 @@ let src_dirname = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.default.dirname
|
|
|
61
61
|
}
|
|
62
62
|
]
|
|
63
63
|
} : issuerInclude, svgRule = rule.oneOf(CHAIN_ID.ONE_OF.SVG);
|
|
64
|
-
options.exclude && svgRule.exclude.add(options.exclude), svgRule.type("javascript/auto").set('issuer', issuer).use(CHAIN_ID.USE.SVGR).loader(
|
|
64
|
+
options.exclude && svgRule.exclude.add(options.exclude), svgRule.type("javascript/auto").set('issuer', issuer).use(CHAIN_ID.USE.SVGR).loader(node_path.resolve(src_dirname, './loader.mjs')).options({
|
|
65
65
|
...svgrOptions,
|
|
66
66
|
exportType
|
|
67
|
-
}).end(), mixedImport && 'named' === exportType && svgRule.use(CHAIN_ID.USE.URL).loader(
|
|
67
|
+
}).end(), mixedImport && 'named' === exportType && svgRule.use(CHAIN_ID.USE.URL).loader(node_path.join(src_dirname, '../compiled', 'url-loader/index.js')).options({
|
|
68
68
|
limit: maxSize,
|
|
69
69
|
name: null == generatorOptions ? void 0 : generatorOptions.filename
|
|
70
70
|
});
|
package/dist/loader.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
const transformSvg =
|
|
1
|
+
import { normalize } from "node:path";
|
|
2
|
+
import { callbackify } from "node:util";
|
|
3
|
+
import { transform } from "@svgr/core";
|
|
4
|
+
import plugin_jsx from "@svgr/plugin-jsx";
|
|
5
|
+
import plugin_svgo from "@svgr/plugin-svgo";
|
|
6
|
+
const transformSvg = callbackify(async (contents, config, state)=>transform(contents, config, state));
|
|
7
7
|
function svgrLoader(contents) {
|
|
8
8
|
this?.cacheable();
|
|
9
9
|
const callback = this.async();
|
|
@@ -18,26 +18,20 @@ function svgrLoader(contents) {
|
|
|
18
18
|
name: '@rsbuild/plugin-svgr',
|
|
19
19
|
previousExport,
|
|
20
20
|
defaultPlugins: [
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
plugin_svgo,
|
|
22
|
+
plugin_jsx
|
|
23
23
|
]
|
|
24
24
|
},
|
|
25
|
-
filePath:
|
|
25
|
+
filePath: normalize(this.resourcePath)
|
|
26
26
|
};
|
|
27
27
|
if (previousExport) this.fs.readFile(this.resourcePath, (err, result)=>{
|
|
28
|
-
if (err)
|
|
29
|
-
callback(err);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
28
|
+
if (err) return void callback(err);
|
|
32
29
|
transformSvg(String(result), options, state, (err, content)=>{
|
|
33
|
-
if (err)
|
|
34
|
-
callback(err);
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
30
|
+
if (err) return void callback(err);
|
|
37
31
|
callback(null, content);
|
|
38
32
|
});
|
|
39
33
|
});
|
|
40
34
|
else transformSvg(contents, options, state, callback);
|
|
41
35
|
}
|
|
42
|
-
const
|
|
43
|
-
export {
|
|
36
|
+
const loader = svgrLoader;
|
|
37
|
+
export { loader as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-svgr",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "SVGR plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
"loader-utils": "^3.3.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@rslib/core": "0.
|
|
35
|
-
"@types/node": "^22.
|
|
34
|
+
"@rslib/core": "0.11.1",
|
|
35
|
+
"@types/node": "^22.17.0",
|
|
36
36
|
"file-loader": "6.2.0",
|
|
37
|
-
"prebundle": "1.
|
|
37
|
+
"prebundle": "1.4.0",
|
|
38
38
|
"svgo": "^3.3.2",
|
|
39
|
-
"typescript": "^5.
|
|
39
|
+
"typescript": "^5.9.2",
|
|
40
40
|
"url-loader": "4.1.1",
|
|
41
|
-
"@rsbuild/core": "1.
|
|
41
|
+
"@rsbuild/core": "1.4.14",
|
|
42
42
|
"@scripts/test-helper": "1.0.1"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public",
|
|
49
|
-
"provenance": true,
|
|
50
49
|
"registry": "https://registry.npmjs.org/"
|
|
51
50
|
},
|
|
52
51
|
"scripts": {
|
|
53
52
|
"build": "rslib build",
|
|
54
53
|
"dev": "rslib build --watch",
|
|
55
|
-
"prebundle": "prebundle"
|
|
54
|
+
"prebundle": "prebundle",
|
|
55
|
+
"bump": "npx bumpp --no-tag"
|
|
56
56
|
}
|
|
57
57
|
}
|