@rsbuild/plugin-svgr 0.4.15 → 0.5.0
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.d.ts +3 -4
- package/dist/index.js +27 -23
- package/dist/index.mjs +28 -24
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -9,11 +9,10 @@ type PluginSvgrOptions = {
|
|
|
9
9
|
*/
|
|
10
10
|
svgrOptions?: Config;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @default
|
|
14
|
-
* @deprecated use `svgrOptions.exportType` instead
|
|
12
|
+
* Whether to allow the use of default import and named import at the same time.
|
|
13
|
+
* @default false
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
mixedImport?: boolean;
|
|
17
16
|
};
|
|
18
17
|
declare const pluginSvgr: (options?: PluginSvgrOptions) => RsbuildPlugin;
|
|
19
18
|
|
package/dist/index.js
CHANGED
|
@@ -81,40 +81,44 @@ var pluginSvgr = (options = {}) => ({
|
|
|
81
81
|
...svgrOptions,
|
|
82
82
|
exportType: "default"
|
|
83
83
|
}).end();
|
|
84
|
+
const { mixedImport = false } = options;
|
|
85
|
+
if (mixedImport || svgrOptions.exportType) {
|
|
86
|
+
const { exportType = mixedImport ? "named" : void 0 } = svgrOptions;
|
|
87
|
+
const svgRule = rule.oneOf(CHAIN_ID.ONE_OF.SVG).type("javascript/auto").set("issuer", [import_shared.SCRIPT_REGEX, /\.mdx$/]).use(CHAIN_ID.USE.SVGR).loader(import_node_path.default.resolve(__dirname, "./loader")).options({
|
|
88
|
+
...svgrOptions,
|
|
89
|
+
exportType
|
|
90
|
+
}).end();
|
|
91
|
+
if (mixedImport && exportType === "named") {
|
|
92
|
+
svgRule.use(CHAIN_ID.USE.URL).loader(import_node_path.default.join(__dirname, "../compiled", "url-loader")).options({
|
|
93
|
+
limit: maxSize,
|
|
94
|
+
name: outputName
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
84
98
|
rule.oneOf(CHAIN_ID.ONE_OF.SVG_ASSET).type("asset").parser({
|
|
99
|
+
// Inline SVG if size < maxSize
|
|
85
100
|
dataUrlCondition: {
|
|
86
101
|
maxSize
|
|
87
102
|
}
|
|
88
103
|
}).set("generator", {
|
|
89
104
|
filename: outputName
|
|
90
|
-
}).set("issuer", {
|
|
91
|
-
// The issuer option ensures that SVGR will only apply if the SVG is imported from a JS file.
|
|
92
|
-
not: [import_shared.SCRIPT_REGEX]
|
|
93
105
|
});
|
|
94
|
-
const { svgDefaultExport = "url" } = options;
|
|
95
|
-
const exportType = svgrOptions.exportType ?? (svgDefaultExport === "url" ? "named" : "default");
|
|
96
|
-
rule.oneOf(CHAIN_ID.ONE_OF.SVG).type("javascript/auto").use(CHAIN_ID.USE.SVGR).loader(import_node_path.default.resolve(__dirname, "./loader")).options({
|
|
97
|
-
...svgrOptions,
|
|
98
|
-
exportType
|
|
99
|
-
}).end().when(
|
|
100
|
-
exportType === "named",
|
|
101
|
-
(c) => c.use(CHAIN_ID.USE.URL).loader(import_node_path.default.join(__dirname, "../compiled", "url-loader")).options({
|
|
102
|
-
limit: maxSize,
|
|
103
|
-
name: outputName
|
|
104
|
-
})
|
|
105
|
-
);
|
|
106
106
|
const jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS);
|
|
107
107
|
[CHAIN_ID.USE.SWC, CHAIN_ID.USE.BABEL].some((jsUseId) => {
|
|
108
108
|
const use = jsRule.uses.get(jsUseId);
|
|
109
|
-
if (use) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
if (!use) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
for (const oneOfId of [
|
|
113
|
+
CHAIN_ID.ONE_OF.SVG,
|
|
114
|
+
CHAIN_ID.ONE_OF.SVG_REACT
|
|
115
|
+
]) {
|
|
116
|
+
if (!rule.oneOfs.has(oneOfId)) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
rule.oneOf(oneOfId).use(jsUseId).before(CHAIN_ID.USE.SVGR).loader(use.get("loader")).options(use.get("options"));
|
|
116
120
|
}
|
|
117
|
-
return
|
|
121
|
+
return true;
|
|
118
122
|
});
|
|
119
123
|
});
|
|
120
124
|
}
|
package/dist/index.mjs
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.48.
|
|
5
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.48.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);
|
|
@@ -64,40 +64,44 @@ var pluginSvgr = (options = {}) => ({
|
|
|
64
64
|
...svgrOptions,
|
|
65
65
|
exportType: "default"
|
|
66
66
|
}).end();
|
|
67
|
+
const { mixedImport = false } = options;
|
|
68
|
+
if (mixedImport || svgrOptions.exportType) {
|
|
69
|
+
const { exportType = mixedImport ? "named" : void 0 } = svgrOptions;
|
|
70
|
+
const svgRule = rule.oneOf(CHAIN_ID.ONE_OF.SVG).type("javascript/auto").set("issuer", [SCRIPT_REGEX, /\.mdx$/]).use(CHAIN_ID.USE.SVGR).loader(path2.resolve(__dirname, "./loader")).options({
|
|
71
|
+
...svgrOptions,
|
|
72
|
+
exportType
|
|
73
|
+
}).end();
|
|
74
|
+
if (mixedImport && exportType === "named") {
|
|
75
|
+
svgRule.use(CHAIN_ID.USE.URL).loader(path2.join(__dirname, "../compiled", "url-loader")).options({
|
|
76
|
+
limit: maxSize,
|
|
77
|
+
name: outputName
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
67
81
|
rule.oneOf(CHAIN_ID.ONE_OF.SVG_ASSET).type("asset").parser({
|
|
82
|
+
// Inline SVG if size < maxSize
|
|
68
83
|
dataUrlCondition: {
|
|
69
84
|
maxSize
|
|
70
85
|
}
|
|
71
86
|
}).set("generator", {
|
|
72
87
|
filename: outputName
|
|
73
|
-
}).set("issuer", {
|
|
74
|
-
// The issuer option ensures that SVGR will only apply if the SVG is imported from a JS file.
|
|
75
|
-
not: [SCRIPT_REGEX]
|
|
76
88
|
});
|
|
77
|
-
const { svgDefaultExport = "url" } = options;
|
|
78
|
-
const exportType = svgrOptions.exportType ?? (svgDefaultExport === "url" ? "named" : "default");
|
|
79
|
-
rule.oneOf(CHAIN_ID.ONE_OF.SVG).type("javascript/auto").use(CHAIN_ID.USE.SVGR).loader(path2.resolve(__dirname, "./loader")).options({
|
|
80
|
-
...svgrOptions,
|
|
81
|
-
exportType
|
|
82
|
-
}).end().when(
|
|
83
|
-
exportType === "named",
|
|
84
|
-
(c) => c.use(CHAIN_ID.USE.URL).loader(path2.join(__dirname, "../compiled", "url-loader")).options({
|
|
85
|
-
limit: maxSize,
|
|
86
|
-
name: outputName
|
|
87
|
-
})
|
|
88
|
-
);
|
|
89
89
|
const jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS);
|
|
90
90
|
[CHAIN_ID.USE.SWC, CHAIN_ID.USE.BABEL].some((jsUseId) => {
|
|
91
91
|
const use = jsRule.uses.get(jsUseId);
|
|
92
|
-
if (use) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
if (!use) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
for (const oneOfId of [
|
|
96
|
+
CHAIN_ID.ONE_OF.SVG,
|
|
97
|
+
CHAIN_ID.ONE_OF.SVG_REACT
|
|
98
|
+
]) {
|
|
99
|
+
if (!rule.oneOfs.has(oneOfId)) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
rule.oneOf(oneOfId).use(jsUseId).before(CHAIN_ID.USE.SVGR).loader(use.get("loader")).options(use.get("options"));
|
|
99
103
|
}
|
|
100
|
-
return
|
|
104
|
+
return true;
|
|
101
105
|
});
|
|
102
106
|
});
|
|
103
107
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-svgr",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "svgr plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
"@svgr/core": "8.1.0",
|
|
27
27
|
"@svgr/plugin-jsx": "8.1.0",
|
|
28
28
|
"@svgr/plugin-svgo": "8.1.0",
|
|
29
|
-
"@rsbuild/shared": "0.
|
|
30
|
-
"@rsbuild/plugin-react": "0.
|
|
29
|
+
"@rsbuild/shared": "0.5.0",
|
|
30
|
+
"@rsbuild/plugin-react": "0.5.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "16.x",
|
|
34
34
|
"typescript": "^5.4.2",
|
|
35
|
-
"@rsbuild/core": "0.
|
|
36
|
-
"@scripts/test-helper": "0.
|
|
35
|
+
"@rsbuild/core": "0.5.0",
|
|
36
|
+
"@scripts/test-helper": "0.5.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@rsbuild/core": "^0.
|
|
39
|
+
"@rsbuild/core": "^0.5.0"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public",
|