@docusaurus/plugin-svgr 4.0.0-canary-6927 → 4.0.0-canary-6929
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/lib/svgrLoader.js +12 -8
- package/package.json +6 -6
- package/src/svgrLoader.ts +13 -12
package/lib/svgrLoader.js
CHANGED
|
@@ -42,14 +42,16 @@ function createSVGRRule(params) {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
function enhanceConfig(config, params) {
|
|
45
|
-
const utils = (0, utils_1.
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
const utils = (0, utils_1.getAssetRuleUtils)(params.isServer);
|
|
46
|
+
const { parentRules, rule: existingSvgRule } = (() => {
|
|
47
|
+
const result = (0, utils_1.findAssetRule)({
|
|
48
|
+
rules: config?.module?.rules,
|
|
49
|
+
test: utils.rules.svgs().test,
|
|
50
|
+
});
|
|
51
|
+
if (!result) {
|
|
50
52
|
throw new Error("Docusaurus built-in SVG rule couldn't be found. The SVGR plugin can't enhance it.");
|
|
51
53
|
}
|
|
52
|
-
return
|
|
54
|
+
return result;
|
|
53
55
|
})();
|
|
54
56
|
const newSvgRule = {
|
|
55
57
|
test: /\.svg$/i,
|
|
@@ -57,6 +59,8 @@ function enhanceConfig(config, params) {
|
|
|
57
59
|
oneOf: [
|
|
58
60
|
{
|
|
59
61
|
use: [createSVGRRule(params)],
|
|
62
|
+
// SVGR components are JS modules, not assets
|
|
63
|
+
type: 'javascript/auto',
|
|
60
64
|
// We don't want to use SVGR loader for non-React source code
|
|
61
65
|
// ie we don't want to use SVGR for CSS files...
|
|
62
66
|
issuer: {
|
|
@@ -70,6 +74,6 @@ function enhanceConfig(config, params) {
|
|
|
70
74
|
// Adding another extra SVG rule (first or last) will not "override"
|
|
71
75
|
// the default: both rules will be applied (from last to bottom) leading to
|
|
72
76
|
// conflicting behavior.
|
|
73
|
-
const index =
|
|
74
|
-
|
|
77
|
+
const index = parentRules.indexOf(existingSvgRule);
|
|
78
|
+
parentRules[index] = newSvgRule;
|
|
75
79
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/plugin-svgr",
|
|
3
|
-
"version": "4.0.0-canary-
|
|
3
|
+
"version": "4.0.0-canary-6929",
|
|
4
4
|
"description": "SVGR plugin for Docusaurus.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@docusaurus/core": "4.0.0-canary-
|
|
18
|
-
"@docusaurus/types": "4.0.0-canary-
|
|
19
|
-
"@docusaurus/utils": "4.0.0-canary-
|
|
20
|
-
"@docusaurus/utils-validation": "4.0.0-canary-
|
|
17
|
+
"@docusaurus/core": "4.0.0-canary-6929",
|
|
18
|
+
"@docusaurus/types": "4.0.0-canary-6929",
|
|
19
|
+
"@docusaurus/utils": "4.0.0-canary-6929",
|
|
20
|
+
"@docusaurus/utils-validation": "4.0.0-canary-6929",
|
|
21
21
|
"@svgr/core": "^8.1.0",
|
|
22
22
|
"@svgr/webpack": "^8.1.0",
|
|
23
23
|
"tslib": "^2.8.1",
|
|
24
24
|
"webpack": "^5.111.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@docusaurus/module-type-aliases": "4.0.0-canary-
|
|
27
|
+
"@docusaurus/module-type-aliases": "4.0.0-canary-6929"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"react": "^19.3.0",
|
package/src/svgrLoader.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {getAssetRuleUtils, findAssetRule} from '@docusaurus/utils';
|
|
9
9
|
|
|
10
10
|
import type {SVGRConfig, SVGOConfig} from './options';
|
|
11
11
|
import type {Configuration, RuleSetRule} from 'webpack';
|
|
@@ -49,20 +49,19 @@ function createSVGRRule(params: Params): RuleSetRule {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export function enhanceConfig(config: Configuration, params: Params): void {
|
|
52
|
-
const utils =
|
|
52
|
+
const utils = getAssetRuleUtils(params.isServer);
|
|
53
53
|
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
)
|
|
60
|
-
if (!rule) {
|
|
54
|
+
const {parentRules, rule: existingSvgRule} = (() => {
|
|
55
|
+
const result = findAssetRule({
|
|
56
|
+
rules: config?.module?.rules as RuleSetRule[],
|
|
57
|
+
test: utils.rules.svgs().test,
|
|
58
|
+
});
|
|
59
|
+
if (!result) {
|
|
61
60
|
throw new Error(
|
|
62
61
|
"Docusaurus built-in SVG rule couldn't be found. The SVGR plugin can't enhance it.",
|
|
63
62
|
);
|
|
64
63
|
}
|
|
65
|
-
return
|
|
64
|
+
return result;
|
|
66
65
|
})();
|
|
67
66
|
|
|
68
67
|
const newSvgRule: RuleSetRule = {
|
|
@@ -71,6 +70,8 @@ export function enhanceConfig(config: Configuration, params: Params): void {
|
|
|
71
70
|
oneOf: [
|
|
72
71
|
{
|
|
73
72
|
use: [createSVGRRule(params)],
|
|
73
|
+
// SVGR components are JS modules, not assets
|
|
74
|
+
type: 'javascript/auto',
|
|
74
75
|
// We don't want to use SVGR loader for non-React source code
|
|
75
76
|
// ie we don't want to use SVGR for CSS files...
|
|
76
77
|
issuer: {
|
|
@@ -85,6 +86,6 @@ export function enhanceConfig(config: Configuration, params: Params): void {
|
|
|
85
86
|
// Adding another extra SVG rule (first or last) will not "override"
|
|
86
87
|
// the default: both rules will be applied (from last to bottom) leading to
|
|
87
88
|
// conflicting behavior.
|
|
88
|
-
const index =
|
|
89
|
-
|
|
89
|
+
const index = parentRules.indexOf(existingSvgRule);
|
|
90
|
+
parentRules[index] = newSvgRule;
|
|
90
91
|
}
|