@rsbuild/plugin-svgr 0.0.17 → 0.0.19
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 +10 -7
- package/dist/index.js +3 -1
- package/dist/index.mjs +86 -0
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { DefaultRsbuildPlugin } from '@rsbuild/shared';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
|
|
3
|
+
type SvgDefaultExport = 'component' | 'url';
|
|
4
|
+
type PluginSvgrOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Configure the default export type of SVG files.
|
|
7
|
+
*/
|
|
8
|
+
svgDefaultExport?: SvgDefaultExport;
|
|
8
9
|
};
|
|
9
|
-
|
|
10
|
+
declare const pluginSvgr: (options?: PluginSvgrOptions) => DefaultRsbuildPlugin;
|
|
11
|
+
|
|
12
|
+
export { PluginSvgrOptions, SvgDefaultExport, pluginSvgr };
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
29
31
|
var src_exports = {};
|
|
30
32
|
__export(src_exports, {
|
|
31
33
|
pluginSvgr: () => pluginSvgr
|
|
@@ -50,7 +52,7 @@ function getSvgoDefaultConfig() {
|
|
|
50
52
|
]
|
|
51
53
|
};
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
var pluginSvgr = (options = {}) => ({
|
|
54
56
|
name: "plugin-svgr",
|
|
55
57
|
setup(api) {
|
|
56
58
|
api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID }) => {
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined")
|
|
5
|
+
return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.40.0_typescript@5.2.2/node_modules/@modern-js/module-tools/shims/esm.js
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
import path from "path";
|
|
12
|
+
|
|
13
|
+
// ../../scripts/require_shims.js
|
|
14
|
+
import { createRequire } from "module";
|
|
15
|
+
global.require = createRequire(import.meta.url);
|
|
16
|
+
|
|
17
|
+
// src/index.ts
|
|
18
|
+
import path2 from "path";
|
|
19
|
+
import {
|
|
20
|
+
JS_REGEX,
|
|
21
|
+
TS_REGEX,
|
|
22
|
+
SVG_REGEX,
|
|
23
|
+
getDistPath,
|
|
24
|
+
getFilename,
|
|
25
|
+
chainStaticAssetRule
|
|
26
|
+
} from "@rsbuild/shared";
|
|
27
|
+
function getSvgoDefaultConfig() {
|
|
28
|
+
return {
|
|
29
|
+
plugins: [
|
|
30
|
+
{
|
|
31
|
+
name: "preset-default",
|
|
32
|
+
params: {
|
|
33
|
+
overrides: {
|
|
34
|
+
// viewBox is required to resize SVGs with CSS.
|
|
35
|
+
// @see https://github.com/svg/svgo/issues/1128
|
|
36
|
+
removeViewBox: false
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"prefixIds"
|
|
41
|
+
]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var pluginSvgr = (options = {}) => ({
|
|
45
|
+
name: "plugin-svgr",
|
|
46
|
+
setup(api) {
|
|
47
|
+
api.modifyBundlerChain(async (chain, { isProd, CHAIN_ID }) => {
|
|
48
|
+
const config = api.getNormalizedConfig();
|
|
49
|
+
const { svgDefaultExport = "url" } = options;
|
|
50
|
+
const assetType = "svg";
|
|
51
|
+
const distDir = getDistPath(config.output, assetType);
|
|
52
|
+
const filename = getFilename(config.output, assetType, isProd);
|
|
53
|
+
const outputName = path2.posix.join(distDir, filename);
|
|
54
|
+
const maxSize = config.output.dataUriLimit[assetType];
|
|
55
|
+
chain.module.rules.delete(CHAIN_ID.RULE.SVG);
|
|
56
|
+
const rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(SVG_REGEX);
|
|
57
|
+
chainStaticAssetRule({
|
|
58
|
+
rule,
|
|
59
|
+
maxSize,
|
|
60
|
+
filename: path2.posix.join(distDir, filename),
|
|
61
|
+
assetType,
|
|
62
|
+
issuer: {
|
|
63
|
+
// The issuer option ensures that SVGR will only apply if the SVG is imported from a JS file.
|
|
64
|
+
not: [JS_REGEX, TS_REGEX]
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
rule.oneOf(CHAIN_ID.ONE_OF.SVG_INLINE).type("asset/inline").resourceQuery(/inline/);
|
|
68
|
+
rule.oneOf(CHAIN_ID.ONE_OF.SVG_URL).type("asset/resource").resourceQuery(/url/).set("generator", {
|
|
69
|
+
filename: outputName
|
|
70
|
+
});
|
|
71
|
+
rule.oneOf(CHAIN_ID.ONE_OF.SVG).type("javascript/auto").use(CHAIN_ID.USE.SVGR).loader(__require.resolve("@svgr/webpack")).options({
|
|
72
|
+
svgo: true,
|
|
73
|
+
svgoConfig: getSvgoDefaultConfig()
|
|
74
|
+
}).end().when(
|
|
75
|
+
svgDefaultExport === "url",
|
|
76
|
+
(c) => c.use(CHAIN_ID.USE.URL).loader(__require.resolve("url-loader")).options({
|
|
77
|
+
limit: config.output.dataUriLimit.svg,
|
|
78
|
+
name: outputName
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
export {
|
|
85
|
+
pluginSvgr
|
|
86
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-svgr",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "svgr plugin for Rsbuild",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
14
15
|
"default": "./dist/index.js"
|
|
15
16
|
}
|
|
16
17
|
},
|
|
@@ -22,13 +23,13 @@
|
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"@svgr/webpack": "8.0.1",
|
|
24
25
|
"url-loader": "4.1.1",
|
|
25
|
-
"@rsbuild/shared": "0.0.
|
|
26
|
+
"@rsbuild/shared": "0.0.19"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@types/node": "^16",
|
|
29
30
|
"typescript": "^5.2.2",
|
|
30
|
-
"@rsbuild/
|
|
31
|
-
"@rsbuild/
|
|
31
|
+
"@rsbuild/core": "0.0.19",
|
|
32
|
+
"@rsbuild/test-helper": "0.0.19"
|
|
32
33
|
},
|
|
33
34
|
"publishConfig": {
|
|
34
35
|
"access": "public",
|