@rsbuild/plugin-svgr 2.0.2 → 2.0.4
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 +25 -20
- package/dist/index.js +11 -5
- package/package.json +14 -14
- package/dist/assetLoader.d.ts +0 -13
- package/dist/loader.d.ts +0 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,40 @@
|
|
|
1
1
|
import type { RsbuildPlugin, Rspack } from '@rsbuild/core';
|
|
2
2
|
import type { Config as BaseSvgrOptions } from '@svgr/core';
|
|
3
3
|
import type { Config as SvgoConfig } from 'svgo';
|
|
4
|
+
// @svgr/core does not have the svgo dependency, so we need to
|
|
5
|
+
// manually specify the svgoConfig type
|
|
4
6
|
type SvgrOptions = Omit<BaseSvgrOptions, 'svgoConfig'> & {
|
|
5
7
|
svgoConfig?: SvgoConfig;
|
|
6
8
|
};
|
|
7
9
|
export type SvgDefaultExport = 'component' | 'url';
|
|
8
10
|
export type PluginSvgrOptions = {
|
|
9
11
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
svgrOptions?: SvgrOptions;
|
|
12
|
+
* Configure SVGR options.
|
|
13
|
+
* @see https://react-svgr.com/docs/options/
|
|
14
|
+
*/ svgrOptions?: SvgrOptions;
|
|
14
15
|
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
mixedImport?: boolean;
|
|
16
|
+
* Whether to allow the use of default import and named import at the same time.
|
|
17
|
+
* @default false
|
|
18
|
+
*/ mixedImport?: boolean;
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
query?: RegExp;
|
|
20
|
+
* Custom query suffix to match SVGR transformation.
|
|
21
|
+
* @default /react/
|
|
22
|
+
*/ query?: RegExp;
|
|
24
23
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
* Whether to enable parallel loader execution, running SVGR loader in worker
|
|
25
|
+
* threads. When enabled, this typically improves build performance when compiling
|
|
26
|
+
* large numbers of SVG modules.
|
|
27
|
+
* @experimental This is an experimental Rspack feature and may not work if your SVGR
|
|
28
|
+
* options contain functions.
|
|
29
|
+
* @default false
|
|
30
|
+
*/ parallel?: boolean;
|
|
28
31
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
* Exclude specific SVG files from SVGR transformation.
|
|
33
|
+
*/ exclude?: Rspack.RuleSetCondition;
|
|
34
|
+
/**
|
|
35
|
+
* Exclude some modules, the SVGs imported by these modules will not be transformed by SVGR.
|
|
36
|
+
*/ excludeImporter?: Rspack.RuleSetCondition;
|
|
32
37
|
};
|
|
33
|
-
export declare const PLUGIN_SVGR_NAME =
|
|
38
|
+
export declare const PLUGIN_SVGR_NAME = 'rsbuild:svgr';
|
|
34
39
|
export declare const pluginSvgr: (options?: PluginSvgrOptions) => RsbuildPlugin;
|
|
35
|
-
export {};
|
|
40
|
+
export { };
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,9 @@ let pluginSvgr = (options = {})=>({
|
|
|
11
11
|
PLUGIN_REACT_NAME
|
|
12
12
|
],
|
|
13
13
|
setup (api) {
|
|
14
|
-
assertCoreVersion(api.context.version)
|
|
14
|
+
assertCoreVersion(api.context.version);
|
|
15
|
+
let { parallel = !1 } = options;
|
|
16
|
+
api.modifyBundlerChain((chain, { CHAIN_ID, environment })=>{
|
|
15
17
|
let { config } = environment, { dataUriLimit } = config.output, maxSize = 'number' == typeof dataUriLimit ? dataUriLimit : dataUriLimit.svg, generatorOptions = {};
|
|
16
18
|
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));
|
|
17
19
|
let rule = chain.module.rule(CHAIN_ID.RULE.SVG).test(SVG_REGEX), svgrOptions = deepmerge({
|
|
@@ -47,10 +49,12 @@ let pluginSvgr = (options = {})=>({
|
|
|
47
49
|
mergedPlugins = mergedPlugins.map((item)=>'object' == typeof item && item.name === plugin.name ? (isMerged = !0, deepmerge(item, plugin)) : item), isMerged || mergedPlugins.push(plugin);
|
|
48
50
|
}
|
|
49
51
|
return config.plugins = mergedPlugins, config;
|
|
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$/)
|
|
52
|
+
})(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$/);
|
|
53
|
+
let svgReactUse = 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({
|
|
51
54
|
...svgrOptions,
|
|
52
55
|
exportType: 'default'
|
|
53
|
-
})
|
|
56
|
+
});
|
|
57
|
+
parallel && svgReactUse.parallel(!0);
|
|
54
58
|
let { mixedImport = !1 } = options;
|
|
55
59
|
if (mixedImport || svgrOptions.exportType) {
|
|
56
60
|
let { exportType = mixedImport ? 'named' : void 0 } = svgrOptions, issuerInclude = [
|
|
@@ -64,10 +68,12 @@ let pluginSvgr = (options = {})=>({
|
|
|
64
68
|
}
|
|
65
69
|
]
|
|
66
70
|
} : issuerInclude, svgRule = rule.oneOf(CHAIN_ID.ONE_OF.SVG);
|
|
67
|
-
options.exclude && svgRule.exclude.add(options.exclude)
|
|
71
|
+
options.exclude && svgRule.exclude.add(options.exclude);
|
|
72
|
+
let svgUse = svgRule.type("javascript/auto").set('issuer', issuer).use(CHAIN_ID.USE.SVGR).loader(node_path.join(import.meta.dirname, 'loader.mjs')).options({
|
|
68
73
|
...svgrOptions,
|
|
69
74
|
exportType
|
|
70
|
-
})
|
|
75
|
+
});
|
|
76
|
+
parallel && svgUse.parallel(!0), mixedImport && 'named' === exportType && svgRule.use(CHAIN_ID.USE.URL).loader(node_path.join(import.meta.dirname, 'assetLoader.mjs')).options({
|
|
71
77
|
limit: maxSize,
|
|
72
78
|
name: generatorOptions?.filename
|
|
73
79
|
});
|
package/package.json
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-svgr",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "SVGR plugin for Rsbuild",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/web-infra-dev/rsbuild",
|
|
8
9
|
"directory": "packages/plugin-svgr"
|
|
9
10
|
},
|
|
10
|
-
"
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
11
14
|
"type": "module",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
12
16
|
"exports": {
|
|
13
17
|
".": {
|
|
14
18
|
"types": "./dist/index.d.ts",
|
|
15
19
|
"default": "./dist/index.js"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public",
|
|
24
|
+
"registry": "https://registry.npmjs.org/"
|
|
25
|
+
},
|
|
22
26
|
"dependencies": {
|
|
23
27
|
"@rsbuild/plugin-react": "^2.0.0",
|
|
24
28
|
"@svgr/core": "8.1.0",
|
|
@@ -29,25 +33,21 @@
|
|
|
29
33
|
},
|
|
30
34
|
"devDependencies": {
|
|
31
35
|
"@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.5",
|
|
32
|
-
"@rslib/core": "0.
|
|
33
|
-
"@types/node": "^24.
|
|
36
|
+
"@rslib/core": "0.22.1",
|
|
37
|
+
"@types/node": "^24.13.2",
|
|
34
38
|
"svgo": "^3.3.3",
|
|
35
39
|
"typescript": "^6.0.3",
|
|
36
|
-
"@rsbuild/core": "2.0.
|
|
40
|
+
"@rsbuild/core": "2.0.15",
|
|
37
41
|
"@scripts/test-helper": "1.0.0"
|
|
38
42
|
},
|
|
39
43
|
"peerDependencies": {
|
|
40
|
-
"@rsbuild/core": "^2.0.0
|
|
44
|
+
"@rsbuild/core": "^2.0.0"
|
|
41
45
|
},
|
|
42
46
|
"peerDependenciesMeta": {
|
|
43
47
|
"@rsbuild/core": {
|
|
44
48
|
"optional": true
|
|
45
49
|
}
|
|
46
50
|
},
|
|
47
|
-
"publishConfig": {
|
|
48
|
-
"access": "public",
|
|
49
|
-
"registry": "https://registry.npmjs.org/"
|
|
50
|
-
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "rslib",
|
|
53
53
|
"dev": "rslib -w"
|
package/dist/assetLoader.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'node:buffer';
|
|
2
|
-
import type { Rspack } from '@rsbuild/core';
|
|
3
|
-
type FilenameTemplate = string | ((resourcePath: string, resourceQuery?: string) => string);
|
|
4
|
-
export type SvgAssetLoaderOptions = {
|
|
5
|
-
limit: number;
|
|
6
|
-
name: FilenameTemplate;
|
|
7
|
-
publicPath?: string | ((url: string, resourcePath: string, context: string) => string);
|
|
8
|
-
};
|
|
9
|
-
type RawLoaderDefinition<OptionsType = {}> = ((this: Rspack.LoaderContext<OptionsType>, content: Buffer | string) => string | Buffer | void | Promise<string | Buffer | void>) & {
|
|
10
|
-
raw: true;
|
|
11
|
-
};
|
|
12
|
-
declare const assetLoader: RawLoaderDefinition<SvgAssetLoaderOptions>;
|
|
13
|
-
export default assetLoader;
|
package/dist/loader.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2017, Smooth Code
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
* modified from https://github.com/gregberge/svgr/blob/7595d378b73d4826a4cead165b3f32386b07315b/packages/webpack/src/index.ts
|
|
7
|
-
*/
|
|
8
|
-
import type { Rspack } from '@rsbuild/core';
|
|
9
|
-
import { type Config } from '@svgr/core';
|
|
10
|
-
declare const svgrLoader: Rspack.LoaderDefinition<Config>;
|
|
11
|
-
export default svgrLoader;
|