@rsbuild/plugin-svgr 2.0.0-alpha.3 → 2.0.0-rc.3
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/assetLoader.d.ts +11 -0
- package/dist/assetLoader.mjs +25 -0
- package/dist/index.js +11 -8
- package/package.json +18 -20
- package/compiled/file-loader/index.d.ts +0 -1
- package/compiled/file-loader/index.js +0 -133
- package/compiled/file-loader/license +0 -20
- package/compiled/file-loader/package.json +0 -1
- package/compiled/url-loader/index.d.ts +0 -1
- package/compiled/url-loader/index.js +0 -281
- package/compiled/url-loader/license +0 -20
- package/compiled/url-loader/package.json +0 -1
- package/dist/index.cjs +0 -136
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Rspack } from '@rsbuild/core';
|
|
2
|
+
type FilenameTemplate = string | ((resourcePath: string, resourceQuery?: string) => string);
|
|
3
|
+
export type SvgAssetLoaderOptions = {
|
|
4
|
+
limit: number;
|
|
5
|
+
name: FilenameTemplate;
|
|
6
|
+
};
|
|
7
|
+
type RawLoaderDefinition<OptionsType = {}> = ((this: Rspack.LoaderContext<OptionsType>, content: Buffer) => string | Buffer | void | Promise<string | Buffer | void>) & {
|
|
8
|
+
raw: true;
|
|
9
|
+
};
|
|
10
|
+
declare const assetLoader: RawLoaderDefinition<SvgAssetLoaderOptions>;
|
|
11
|
+
export default assetLoader;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { interpolateName } from "loader-utils";
|
|
3
|
+
const SVG_MIME_TYPE = 'image/svg+xml';
|
|
4
|
+
const HASH_TEMPLATE_REGEX = /\[(?:[^:\]]+:)?(?:hash|contenthash)(?::[^\]]+)?]/i;
|
|
5
|
+
const normalizePath = (value)=>value.replace(/\\/g, '/');
|
|
6
|
+
const assetLoader = function(content) {
|
|
7
|
+
const { limit, name } = this.getOptions();
|
|
8
|
+
if (content.length <= limit) {
|
|
9
|
+
const dataUrl = `data:${SVG_MIME_TYPE};base64,${content.toString('base64')}`;
|
|
10
|
+
return `export default ${JSON.stringify(dataUrl)}`;
|
|
11
|
+
}
|
|
12
|
+
const filename = interpolateName(this, name, {
|
|
13
|
+
context: this.rootContext,
|
|
14
|
+
content
|
|
15
|
+
});
|
|
16
|
+
const assetInfo = {
|
|
17
|
+
sourceFilename: normalizePath(node_path.relative(this.rootContext, this.resourcePath))
|
|
18
|
+
};
|
|
19
|
+
if ('string' == typeof name && HASH_TEMPLATE_REGEX.test(name)) assetInfo.immutable = true;
|
|
20
|
+
this.emitFile(filename, content, void 0, assetInfo);
|
|
21
|
+
return `export default __webpack_public_path__ + ${JSON.stringify(filename)};`;
|
|
22
|
+
};
|
|
23
|
+
assetLoader.raw = true;
|
|
24
|
+
const src_assetLoader = assetLoader;
|
|
25
|
+
export default src_assetLoader;
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import node_path from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
2
|
import { PLUGIN_REACT_NAME } from "@rsbuild/plugin-react";
|
|
4
3
|
import deepmerge from "deepmerge";
|
|
5
|
-
let
|
|
4
|
+
let SVG_REGEX = /\.svg$/, PLUGIN_SVGR_NAME = 'rsbuild:svgr';
|
|
5
|
+
function assertCoreVersion(version) {
|
|
6
|
+
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.');
|
|
7
|
+
}
|
|
8
|
+
let pluginSvgr = (options = {})=>({
|
|
6
9
|
name: PLUGIN_SVGR_NAME,
|
|
7
10
|
pre: [
|
|
8
11
|
PLUGIN_REACT_NAME
|
|
9
12
|
],
|
|
10
13
|
setup (api) {
|
|
11
|
-
api.modifyBundlerChain((chain, { CHAIN_ID, environment })=>{
|
|
14
|
+
assertCoreVersion(api.context.version), api.modifyBundlerChain((chain, { CHAIN_ID, environment })=>{
|
|
12
15
|
let { config } = environment, { dataUriLimit } = config.output, maxSize = 'number' == typeof dataUriLimit ? dataUriLimit : dataUriLimit.svg, generatorOptions = {};
|
|
13
16
|
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
17
|
let rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(SVG_REGEX), svgrOptions = deepmerge({
|
|
@@ -44,7 +47,7 @@ let src_dirname = node_path.dirname(fileURLToPath(import.meta.url)), SVG_REGEX =
|
|
|
44
47
|
mergedPlugins = mergedPlugins.map((item)=>'object' == typeof item && item.name === plugin.name ? (isMerged = !0, deepmerge(item, plugin)) : item), isMerged || mergedPlugins.push(plugin);
|
|
45
48
|
}
|
|
46
49
|
return config.plugins = mergedPlugins, config;
|
|
47
|
-
})(svgrOptions.svgoConfig), rule.oneOf(CHAIN_ID.ONE_OF.SVG_URL).type('asset/resource').resourceQuery(/^\?
|
|
50
|
+
})(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(node_path.join(import.meta.dirname, 'loader.mjs')).options({
|
|
48
51
|
...svgrOptions,
|
|
49
52
|
exportType: 'default'
|
|
50
53
|
}).end();
|
|
@@ -61,10 +64,10 @@ let src_dirname = node_path.dirname(fileURLToPath(import.meta.url)), SVG_REGEX =
|
|
|
61
64
|
}
|
|
62
65
|
]
|
|
63
66
|
} : 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(node_path.
|
|
67
|
+
options.exclude && svgRule.exclude.add(options.exclude), svgRule.type("javascript/auto").set('issuer', issuer).use(CHAIN_ID.USE.SVGR).loader(node_path.join(import.meta.dirname, 'loader.mjs')).options({
|
|
65
68
|
...svgrOptions,
|
|
66
69
|
exportType
|
|
67
|
-
}).end(), mixedImport && 'named' === exportType && svgRule.use(CHAIN_ID.USE.URL).loader(node_path.join(
|
|
70
|
+
}).end(), mixedImport && 'named' === exportType && svgRule.use(CHAIN_ID.USE.URL).loader(node_path.join(import.meta.dirname, 'assetLoader.mjs')).options({
|
|
68
71
|
limit: maxSize,
|
|
69
72
|
name: generatorOptions?.filename
|
|
70
73
|
});
|
|
@@ -74,12 +77,12 @@ let src_dirname = node_path.dirname(fileURLToPath(import.meta.url)), SVG_REGEX =
|
|
|
74
77
|
maxSize
|
|
75
78
|
}
|
|
76
79
|
}).set('generator', generatorOptions);
|
|
77
|
-
let
|
|
80
|
+
let jsMainRule = chain.module.rules.get(CHAIN_ID.RULE.JS).oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN);
|
|
78
81
|
[
|
|
79
82
|
CHAIN_ID.USE.SWC,
|
|
80
83
|
CHAIN_ID.USE.BABEL
|
|
81
84
|
].some((jsUseId)=>{
|
|
82
|
-
let use =
|
|
85
|
+
let use = jsMainRule.uses.get(jsUseId);
|
|
83
86
|
if (!use) return !1;
|
|
84
87
|
for (let oneOfId of [
|
|
85
88
|
CHAIN_ID.ONE_OF.SVG,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-svgr",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-rc.3",
|
|
4
4
|
"description": "SVGR plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,18 +12,15 @@
|
|
|
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
|
-
"dist"
|
|
23
|
-
"compiled"
|
|
20
|
+
"dist"
|
|
24
21
|
],
|
|
25
22
|
"dependencies": {
|
|
26
|
-
"@rsbuild/plugin-react": "^2.0.0-
|
|
23
|
+
"@rsbuild/plugin-react": "^2.0.0-rc.3",
|
|
27
24
|
"@svgr/core": "8.1.0",
|
|
28
25
|
"@svgr/plugin-jsx": "8.1.0",
|
|
29
26
|
"@svgr/plugin-svgo": "8.1.0",
|
|
@@ -31,27 +28,28 @@
|
|
|
31
28
|
"loader-utils": "^3.3.1"
|
|
32
29
|
},
|
|
33
30
|
"devDependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"@rsbuild/core": "2.0.0-alpha.3",
|
|
42
|
-
"@scripts/test-helper": "1.0.1"
|
|
31
|
+
"@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.5",
|
|
32
|
+
"@rslib/core": "0.21.0",
|
|
33
|
+
"@types/node": "^24.12.2",
|
|
34
|
+
"svgo": "^3.3.3",
|
|
35
|
+
"typescript": "^6.0.2",
|
|
36
|
+
"@scripts/test-helper": "1.0.0",
|
|
37
|
+
"@rsbuild/core": "2.0.0-rc.3"
|
|
43
38
|
},
|
|
44
39
|
"peerDependencies": {
|
|
45
40
|
"@rsbuild/core": "^2.0.0-0"
|
|
46
41
|
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"@rsbuild/core": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public",
|
|
49
49
|
"registry": "https://registry.npmjs.org/"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
|
-
"build": "rslib
|
|
53
|
-
"dev": "rslib
|
|
54
|
-
"prebundle": "prebundle",
|
|
55
|
-
"bump": "pnpx bumpp --no-tag"
|
|
52
|
+
"build": "rslib",
|
|
53
|
+
"dev": "rslib -w"
|
|
56
54
|
}
|
|
57
55
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export = any;
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
"use strict";
|
|
3
|
-
var __webpack_modules__ = {
|
|
4
|
-
910: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
5
|
-
const loader = __nccwpck_require__(156);
|
|
6
|
-
module.exports = loader.default;
|
|
7
|
-
module.exports.raw = loader.raw;
|
|
8
|
-
},
|
|
9
|
-
156: (__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports["default"] = loader;
|
|
12
|
-
exports.raw = void 0;
|
|
13
|
-
var _path = _interopRequireDefault(__nccwpck_require__(928));
|
|
14
|
-
var _loaderUtils = __nccwpck_require__(328);
|
|
15
|
-
var _utils = __nccwpck_require__(245);
|
|
16
|
-
function _interopRequireDefault(obj) {
|
|
17
|
-
return obj && obj.__esModule ? obj : { default: obj };
|
|
18
|
-
}
|
|
19
|
-
function loader(content) {
|
|
20
|
-
const options = this.getOptions() || {};
|
|
21
|
-
const context = options.context || this.rootContext;
|
|
22
|
-
const name = options.name || "[contenthash].[ext]";
|
|
23
|
-
const url = (0, _loaderUtils.interpolateName)(this, name, {
|
|
24
|
-
context,
|
|
25
|
-
content,
|
|
26
|
-
regExp: options.regExp,
|
|
27
|
-
});
|
|
28
|
-
let outputPath = url;
|
|
29
|
-
if (options.outputPath) {
|
|
30
|
-
if (typeof options.outputPath === "function") {
|
|
31
|
-
outputPath = options.outputPath(url, this.resourcePath, context);
|
|
32
|
-
} else {
|
|
33
|
-
outputPath = _path.default.posix.join(options.outputPath, url);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
let publicPath = `__webpack_public_path__ + ${JSON.stringify(outputPath)}`;
|
|
37
|
-
if (options.publicPath) {
|
|
38
|
-
if (typeof options.publicPath === "function") {
|
|
39
|
-
publicPath = options.publicPath(url, this.resourcePath, context);
|
|
40
|
-
} else {
|
|
41
|
-
publicPath = `${options.publicPath.endsWith("/") ? options.publicPath : `${options.publicPath}/`}${url}`;
|
|
42
|
-
}
|
|
43
|
-
publicPath = JSON.stringify(publicPath);
|
|
44
|
-
}
|
|
45
|
-
if (options.postTransformPublicPath) {
|
|
46
|
-
publicPath = options.postTransformPublicPath(publicPath);
|
|
47
|
-
}
|
|
48
|
-
if (typeof options.emitFile === "undefined" || options.emitFile) {
|
|
49
|
-
const assetInfo = {};
|
|
50
|
-
if (typeof name === "string") {
|
|
51
|
-
let normalizedName = name;
|
|
52
|
-
const idx = normalizedName.indexOf("?");
|
|
53
|
-
if (idx >= 0) {
|
|
54
|
-
normalizedName = normalizedName.substr(0, idx);
|
|
55
|
-
}
|
|
56
|
-
const isImmutable =
|
|
57
|
-
/\[([^:\]]+:)?(hash|contenthash)(:[^\]]+)?]/gi.test(
|
|
58
|
-
normalizedName,
|
|
59
|
-
);
|
|
60
|
-
if (isImmutable === true) {
|
|
61
|
-
assetInfo.immutable = true;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
assetInfo.sourceFilename = (0, _utils.normalizePath)(
|
|
65
|
-
_path.default.relative(this.rootContext, this.resourcePath),
|
|
66
|
-
);
|
|
67
|
-
this.emitFile(outputPath, content, null, assetInfo);
|
|
68
|
-
}
|
|
69
|
-
const esModule =
|
|
70
|
-
typeof options.esModule !== "undefined" ? options.esModule : true;
|
|
71
|
-
return `${esModule ? "export default" : "module.exports ="} ${publicPath};`;
|
|
72
|
-
}
|
|
73
|
-
const raw = true;
|
|
74
|
-
exports.raw = raw;
|
|
75
|
-
},
|
|
76
|
-
245: (__unused_webpack_module, exports) => {
|
|
77
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
78
|
-
exports.normalizePath = normalizePath;
|
|
79
|
-
function normalizePath(path, stripTrailing) {
|
|
80
|
-
if (path === "\\" || path === "/") {
|
|
81
|
-
return "/";
|
|
82
|
-
}
|
|
83
|
-
const len = path.length;
|
|
84
|
-
if (len <= 1) {
|
|
85
|
-
return path;
|
|
86
|
-
}
|
|
87
|
-
let prefix = "";
|
|
88
|
-
if (len > 4 && path[3] === "\\") {
|
|
89
|
-
const ch = path[2];
|
|
90
|
-
if ((ch === "?" || ch === ".") && path.slice(0, 2) === "\\\\") {
|
|
91
|
-
path = path.slice(2);
|
|
92
|
-
prefix = "//";
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const segs = path.split(/[/\\]+/);
|
|
96
|
-
if (stripTrailing !== false && segs[segs.length - 1] === "") {
|
|
97
|
-
segs.pop();
|
|
98
|
-
}
|
|
99
|
-
return prefix + segs.join("/");
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
328: (module) => {
|
|
103
|
-
module.exports = require("loader-utils");
|
|
104
|
-
},
|
|
105
|
-
928: (module) => {
|
|
106
|
-
module.exports = require("path");
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
var __webpack_module_cache__ = {};
|
|
110
|
-
function __nccwpck_require__(moduleId) {
|
|
111
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
112
|
-
if (cachedModule !== undefined) {
|
|
113
|
-
return cachedModule.exports;
|
|
114
|
-
}
|
|
115
|
-
var module = (__webpack_module_cache__[moduleId] = { exports: {} });
|
|
116
|
-
var threw = true;
|
|
117
|
-
try {
|
|
118
|
-
__webpack_modules__[moduleId](
|
|
119
|
-
module,
|
|
120
|
-
module.exports,
|
|
121
|
-
__nccwpck_require__,
|
|
122
|
-
);
|
|
123
|
-
threw = false;
|
|
124
|
-
} finally {
|
|
125
|
-
if (threw) delete __webpack_module_cache__[moduleId];
|
|
126
|
-
}
|
|
127
|
-
return module.exports;
|
|
128
|
-
}
|
|
129
|
-
if (typeof __nccwpck_require__ !== "undefined")
|
|
130
|
-
__nccwpck_require__.ab = __dirname + "/";
|
|
131
|
-
var __webpack_exports__ = __nccwpck_require__(910);
|
|
132
|
-
module.exports = __webpack_exports__;
|
|
133
|
-
})();
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
Copyright JS Foundation and other contributors
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
'Software'), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
|
12
|
-
included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"name":"file-loader","author":"Tobias Koppers @sokra","version":"6.2.0","funding":{"type":"opencollective","url":"https://opencollective.com/webpack"},"license":"MIT","types":"index.d.ts","type":"commonjs"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export = any;
|