@rsbuild/plugin-svgr 1.3.1 → 2.0.0-rc.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/compiled/url-loader/index.js +6 -6
- package/dist/index.js +7 -3
- package/package.json +13 -16
- package/dist/index.cjs +0 -136
|
@@ -107,20 +107,20 @@
|
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
|
-
|
|
110
|
+
899: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
111
111
|
"use strict";
|
|
112
|
-
const loader = __nccwpck_require__(
|
|
112
|
+
const loader = __nccwpck_require__(29);
|
|
113
113
|
module.exports = loader.default;
|
|
114
114
|
module.exports.raw = loader.raw;
|
|
115
115
|
},
|
|
116
|
-
|
|
116
|
+
29: (__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__(574));
|
|
123
|
-
var _normalizeFallback = _interopRequireDefault(__nccwpck_require__(
|
|
123
|
+
var _normalizeFallback = _interopRequireDefault(__nccwpck_require__(358));
|
|
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
|
+
358: (__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__(899);
|
|
280
280
|
module.exports = __webpack_exports__;
|
|
281
281
|
})();
|
package/dist/index.js
CHANGED
|
@@ -2,13 +2,17 @@ import node_path from "node:path";
|
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { PLUGIN_REACT_NAME } from "@rsbuild/plugin-react";
|
|
4
4
|
import deepmerge from "deepmerge";
|
|
5
|
-
let src_dirname = node_path.dirname(fileURLToPath(import.meta.url)), SVG_REGEX = /\.svg$/, PLUGIN_SVGR_NAME = 'rsbuild:svgr'
|
|
5
|
+
let src_dirname = node_path.dirname(fileURLToPath(import.meta.url)), SVG_REGEX = /\.svg$/, PLUGIN_SVGR_NAME = 'rsbuild:svgr';
|
|
6
|
+
function assertCoreVersion(version) {
|
|
7
|
+
if ('1' === version.split('.')[0]) throw Error('"@rsbuild/plugin-svgr" v2 requires "@rsbuild/core" >= 2.0. Please upgrade "@rsbuild/core" or use "@rsbuild/plugin-svgr" v1.');
|
|
8
|
+
}
|
|
9
|
+
let pluginSvgr = (options = {})=>({
|
|
6
10
|
name: PLUGIN_SVGR_NAME,
|
|
7
11
|
pre: [
|
|
8
12
|
PLUGIN_REACT_NAME
|
|
9
13
|
],
|
|
10
14
|
setup (api) {
|
|
11
|
-
api.modifyBundlerChain((chain, { CHAIN_ID, environment })=>{
|
|
15
|
+
assertCoreVersion(api.context.version), api.modifyBundlerChain((chain, { CHAIN_ID, environment })=>{
|
|
12
16
|
let { config } = environment, { dataUriLimit } = config.output, maxSize = 'number' == typeof dataUriLimit ? dataUriLimit : dataUriLimit.svg, generatorOptions = {};
|
|
13
17
|
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));
|
|
14
18
|
let rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(SVG_REGEX), svgrOptions = deepmerge({
|
|
@@ -74,7 +78,7 @@ let src_dirname = node_path.dirname(fileURLToPath(import.meta.url)), SVG_REGEX =
|
|
|
74
78
|
maxSize
|
|
75
79
|
}
|
|
76
80
|
}).set('generator', generatorOptions);
|
|
77
|
-
let
|
|
81
|
+
let jsMainRule = chain.module.rules.get(CHAIN_ID.RULE.JS).oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN);
|
|
78
82
|
[
|
|
79
83
|
CHAIN_ID.USE.SWC,
|
|
80
84
|
CHAIN_ID.USE.BABEL
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-svgr",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc.2",
|
|
4
4
|
"description": "SVGR plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,18 +12,16 @@
|
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
|
-
"
|
|
16
|
-
"require": "./dist/index.cjs"
|
|
15
|
+
"default": "./dist/index.js"
|
|
17
16
|
}
|
|
18
17
|
},
|
|
19
|
-
"main": "./dist/index.cjs",
|
|
20
18
|
"types": "./dist/index.d.ts",
|
|
21
19
|
"files": [
|
|
22
20
|
"dist",
|
|
23
21
|
"compiled"
|
|
24
22
|
],
|
|
25
23
|
"dependencies": {
|
|
26
|
-
"@rsbuild/plugin-react": "^
|
|
24
|
+
"@rsbuild/plugin-react": "^2.0.0-rc.2",
|
|
27
25
|
"@svgr/core": "8.1.0",
|
|
28
26
|
"@svgr/plugin-jsx": "8.1.0",
|
|
29
27
|
"@svgr/plugin-svgo": "8.1.0",
|
|
@@ -31,19 +29,19 @@
|
|
|
31
29
|
"loader-utils": "^3.3.1"
|
|
32
30
|
},
|
|
33
31
|
"devDependencies": {
|
|
34
|
-
"@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.
|
|
35
|
-
"@rslib/core": "0.
|
|
36
|
-
"@types/node": "^24.12.
|
|
32
|
+
"@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.5",
|
|
33
|
+
"@rslib/core": "0.21.0",
|
|
34
|
+
"@types/node": "^24.12.2",
|
|
37
35
|
"file-loader": "6.2.0",
|
|
38
|
-
"prebundle": "1.6.
|
|
36
|
+
"prebundle": "1.6.4",
|
|
39
37
|
"svgo": "^3.3.3",
|
|
40
|
-
"typescript": "^
|
|
38
|
+
"typescript": "^6.0.2",
|
|
41
39
|
"url-loader": "4.1.1",
|
|
42
|
-
"@rsbuild/core": "2.0.0-
|
|
40
|
+
"@rsbuild/core": "2.0.0-rc.1",
|
|
43
41
|
"@scripts/test-helper": "1.0.0"
|
|
44
42
|
},
|
|
45
43
|
"peerDependencies": {
|
|
46
|
-
"@rsbuild/core": "^
|
|
44
|
+
"@rsbuild/core": "^2.0.0-0"
|
|
47
45
|
},
|
|
48
46
|
"peerDependenciesMeta": {
|
|
49
47
|
"@rsbuild/core": {
|
|
@@ -55,9 +53,8 @@
|
|
|
55
53
|
"registry": "https://registry.npmjs.org/"
|
|
56
54
|
},
|
|
57
55
|
"scripts": {
|
|
58
|
-
"build": "rslib
|
|
59
|
-
"dev": "rslib
|
|
60
|
-
"prebundle": "prebundle"
|
|
61
|
-
"bump": "pnpx bumpp --no-tag"
|
|
56
|
+
"build": "rslib",
|
|
57
|
+
"dev": "rslib -w",
|
|
58
|
+
"prebundle": "prebundle"
|
|
62
59
|
}
|
|
63
60
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const __rslib_import_meta_url__ = "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
3
|
-
var __webpack_require__ = {};
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module.default : ()=>module;
|
|
6
|
-
return __webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
}), getter;
|
|
9
|
-
}, __webpack_require__.d = (exports1, definition)=>{
|
|
10
|
-
for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
|
|
11
|
-
enumerable: !0,
|
|
12
|
-
get: definition[key]
|
|
13
|
-
});
|
|
14
|
-
}, __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop), __webpack_require__.r = (exports1)=>{
|
|
15
|
-
"u" > typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
16
|
-
value: 'Module'
|
|
17
|
-
}), Object.defineProperty(exports1, '__esModule', {
|
|
18
|
-
value: !0
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __webpack_exports__ = {};
|
|
22
|
-
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
23
|
-
pluginSvgr: ()=>pluginSvgr,
|
|
24
|
-
PLUGIN_SVGR_NAME: ()=>PLUGIN_SVGR_NAME
|
|
25
|
-
});
|
|
26
|
-
const external_node_path_namespaceObject = require("node:path");
|
|
27
|
-
var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
|
|
28
|
-
const external_node_url_namespaceObject = require("node:url"), plugin_react_namespaceObject = require("@rsbuild/plugin-react"), external_deepmerge_namespaceObject = require("deepmerge");
|
|
29
|
-
var external_deepmerge_default = __webpack_require__.n(external_deepmerge_namespaceObject);
|
|
30
|
-
const src_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__)), SVG_REGEX = /\.svg$/, getSvgoDefaultConfig = ()=>({
|
|
31
|
-
plugins: [
|
|
32
|
-
{
|
|
33
|
-
name: 'preset-default',
|
|
34
|
-
params: {
|
|
35
|
-
overrides: {
|
|
36
|
-
removeViewBox: !1
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
'prefixIds'
|
|
41
|
-
]
|
|
42
|
-
}), dedupeSvgoPlugins = (config)=>{
|
|
43
|
-
if (!config.plugins) return config;
|
|
44
|
-
let mergedPlugins = [];
|
|
45
|
-
for (let plugin of config.plugins){
|
|
46
|
-
if ('string' == typeof plugin) {
|
|
47
|
-
mergedPlugins.find((item)=>item === plugin || 'object' == typeof item && item.name === plugin) || mergedPlugins.push(plugin);
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
let strIndex = mergedPlugins.findIndex((item)=>'string' == typeof item && item === plugin.name);
|
|
51
|
-
if (-1 !== strIndex) {
|
|
52
|
-
mergedPlugins[strIndex] = plugin;
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
let isMerged = !1;
|
|
56
|
-
mergedPlugins = mergedPlugins.map((item)=>'object' == typeof item && item.name === plugin.name ? (isMerged = !0, external_deepmerge_default()(item, plugin)) : item), isMerged || mergedPlugins.push(plugin);
|
|
57
|
-
}
|
|
58
|
-
return config.plugins = mergedPlugins, config;
|
|
59
|
-
}, PLUGIN_SVGR_NAME = 'rsbuild:svgr', pluginSvgr = (options = {})=>({
|
|
60
|
-
name: PLUGIN_SVGR_NAME,
|
|
61
|
-
pre: [
|
|
62
|
-
plugin_react_namespaceObject.PLUGIN_REACT_NAME
|
|
63
|
-
],
|
|
64
|
-
setup (api) {
|
|
65
|
-
api.modifyBundlerChain((chain, { CHAIN_ID, environment })=>{
|
|
66
|
-
let { config } = environment, { dataUriLimit } = config.output, maxSize = 'number' == typeof dataUriLimit ? dataUriLimit : dataUriLimit.svg, generatorOptions = {};
|
|
67
|
-
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));
|
|
68
|
-
let rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(SVG_REGEX), svgrOptions = external_deepmerge_default()({
|
|
69
|
-
svgo: !0,
|
|
70
|
-
svgoConfig: getSvgoDefaultConfig()
|
|
71
|
-
}, options.svgrOptions || {});
|
|
72
|
-
svgrOptions.svgoConfig = dedupeSvgoPlugins(svgrOptions.svgoConfig), rule.oneOf(CHAIN_ID.ONE_OF.SVG_URL).type('asset/resource').resourceQuery(/^\?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
|
-
...svgrOptions,
|
|
74
|
-
exportType: 'default'
|
|
75
|
-
}).end();
|
|
76
|
-
let { mixedImport = !1 } = options;
|
|
77
|
-
if (mixedImport || svgrOptions.exportType) {
|
|
78
|
-
let { exportType = mixedImport ? 'named' : void 0 } = svgrOptions, issuerInclude = [
|
|
79
|
-
/\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)$/,
|
|
80
|
-
/\.mdx$/
|
|
81
|
-
], issuer = options.excludeImporter ? {
|
|
82
|
-
and: [
|
|
83
|
-
issuerInclude,
|
|
84
|
-
{
|
|
85
|
-
not: options.excludeImporter
|
|
86
|
-
}
|
|
87
|
-
]
|
|
88
|
-
} : issuerInclude, svgRule = rule.oneOf(CHAIN_ID.ONE_OF.SVG);
|
|
89
|
-
options.exclude && svgRule.exclude.add(options.exclude), svgRule.type("javascript/auto").set('issuer', issuer).use(CHAIN_ID.USE.SVGR).loader(external_node_path_default().resolve(src_dirname, './loader.mjs')).options({
|
|
90
|
-
...svgrOptions,
|
|
91
|
-
exportType
|
|
92
|
-
}).end(), mixedImport && 'named' === exportType && svgRule.use(CHAIN_ID.USE.URL).loader(external_node_path_default().join(src_dirname, '../compiled', 'url-loader/index.js')).options({
|
|
93
|
-
limit: maxSize,
|
|
94
|
-
name: generatorOptions?.filename
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
rule.oneOf(CHAIN_ID.ONE_OF.SVG_ASSET).type('asset').parser({
|
|
98
|
-
dataUrlCondition: {
|
|
99
|
-
maxSize
|
|
100
|
-
}
|
|
101
|
-
}).set('generator', generatorOptions);
|
|
102
|
-
let isV1 = api.context.version.startsWith('1.'), jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS), jsMainRule = isV1 ? jsRule : jsRule.oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN);
|
|
103
|
-
[
|
|
104
|
-
CHAIN_ID.USE.SWC,
|
|
105
|
-
CHAIN_ID.USE.BABEL
|
|
106
|
-
].some((jsUseId)=>{
|
|
107
|
-
let use = jsMainRule.uses.get(jsUseId);
|
|
108
|
-
if (!use) return !1;
|
|
109
|
-
for (let oneOfId of [
|
|
110
|
-
CHAIN_ID.ONE_OF.SVG,
|
|
111
|
-
CHAIN_ID.ONE_OF.SVG_REACT
|
|
112
|
-
]){
|
|
113
|
-
if (!rule.oneOfs.has(oneOfId)) continue;
|
|
114
|
-
let loaderOptions = use.get('options');
|
|
115
|
-
jsUseId === CHAIN_ID.USE.SWC && (loaderOptions = external_deepmerge_default()(loaderOptions, {
|
|
116
|
-
jsc: {
|
|
117
|
-
transform: {
|
|
118
|
-
react: {
|
|
119
|
-
refresh: !1
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
})), rule.oneOf(oneOfId).use(jsUseId).before(CHAIN_ID.USE.SVGR).loader(use.get('loader')).options(loaderOptions);
|
|
124
|
-
}
|
|
125
|
-
return !0;
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
for(var __rspack_i in exports.PLUGIN_SVGR_NAME = __webpack_exports__.PLUGIN_SVGR_NAME, exports.pluginSvgr = __webpack_exports__.pluginSvgr, __webpack_exports__)-1 === [
|
|
131
|
-
"PLUGIN_SVGR_NAME",
|
|
132
|
-
"pluginSvgr"
|
|
133
|
-
].indexOf(__rspack_i) && (exports[__rspack_i] = __webpack_exports__[__rspack_i]);
|
|
134
|
-
Object.defineProperty(exports, '__esModule', {
|
|
135
|
-
value: !0
|
|
136
|
-
});
|