@rsbuild/plugin-svgr 2.0.3 → 2.0.5

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 CHANGED
@@ -21,6 +21,17 @@ export type PluginSvgrOptions = {
21
21
  * @default /react/
22
22
  */ query?: RegExp;
23
23
  /**
24
+ * Whether to transform SVG modules into React components in parallel using worker
25
+ * threads. When enabled, SVG modules are processed across multiple worker threads,
26
+ * reducing pressure on the main thread and improving overall build performance
27
+ * when compiling large numbers of SVG modules.
28
+ *
29
+ * Options transferred to worker threads must comply with the HTML structured clone
30
+ * algorithm. For example, functions cannot be passed as options.
31
+ * @see https://nodejs.org/api/worker_threads.html#portpostmessagevalue-transferlist
32
+ * @default false
33
+ */ parallel?: boolean;
34
+ /**
24
35
  * Exclude specific SVG files from SVGR transformation.
25
36
  */ exclude?: Rspack.RuleSetCondition;
26
37
  /**
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), api.modifyBundlerChain((chain, { CHAIN_ID, environment })=>{
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,14 @@ 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$/), 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({
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_TEXT && rule.oneOf(CHAIN_ID.ONE_OF.SVG_TEXT).type('asset/source').with({
53
+ type: 'text'
54
+ }), CHAIN_ID.ONE_OF.SVG_RAW && rule.oneOf(CHAIN_ID.ONE_OF.SVG_RAW).type('asset/source').resourceQuery(/^\?raw$/);
55
+ 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
56
  ...svgrOptions,
52
57
  exportType: 'default'
53
- }).end();
58
+ });
59
+ parallel && svgReactUse.parallel(!0);
54
60
  let { mixedImport = !1 } = options;
55
61
  if (mixedImport || svgrOptions.exportType) {
56
62
  let { exportType = mixedImport ? 'named' : void 0 } = svgrOptions, issuerInclude = [
@@ -64,10 +70,12 @@ let pluginSvgr = (options = {})=>({
64
70
  }
65
71
  ]
66
72
  } : issuerInclude, svgRule = rule.oneOf(CHAIN_ID.ONE_OF.SVG);
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({
73
+ options.exclude && svgRule.exclude.add(options.exclude);
74
+ 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
75
  ...svgrOptions,
69
76
  exportType
70
- }).end(), mixedImport && 'named' === exportType && svgRule.use(CHAIN_ID.USE.URL).loader(node_path.join(import.meta.dirname, 'assetLoader.mjs')).options({
77
+ });
78
+ parallel && svgUse.parallel(!0), mixedImport && 'named' === exportType && svgRule.use(CHAIN_ID.USE.URL).loader(node_path.join(import.meta.dirname, 'assetLoader.mjs')).options({
71
79
  limit: maxSize,
72
80
  name: generatorOptions?.filename
73
81
  });
package/package.json CHANGED
@@ -1,24 +1,32 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-svgr",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "SVGR plugin for Rsbuild",
5
+ "homepage": "https://rsbuild.rs",
6
+ "bugs": {
7
+ "url": "https://github.com/web-infra-dev/rsbuild/issues"
8
+ },
9
+ "license": "MIT",
5
10
  "repository": {
6
11
  "type": "git",
7
12
  "url": "https://github.com/web-infra-dev/rsbuild",
8
13
  "directory": "packages/plugin-svgr"
9
14
  },
10
- "license": "MIT",
15
+ "files": [
16
+ "dist"
17
+ ],
11
18
  "type": "module",
19
+ "types": "./dist/index.d.ts",
12
20
  "exports": {
13
21
  ".": {
14
22
  "types": "./dist/index.d.ts",
15
23
  "default": "./dist/index.js"
16
24
  }
17
25
  },
18
- "types": "./dist/index.d.ts",
19
- "files": [
20
- "dist"
21
- ],
26
+ "publishConfig": {
27
+ "access": "public",
28
+ "registry": "https://registry.npmjs.org/"
29
+ },
22
30
  "dependencies": {
23
31
  "@rsbuild/plugin-react": "^2.0.0",
24
32
  "@svgr/core": "8.1.0",
@@ -29,25 +37,21 @@
29
37
  },
30
38
  "devDependencies": {
31
39
  "@rsbuild/core-v1": "npm:@rsbuild/core@^1.7.5",
32
- "@rslib/core": "0.22.0",
33
- "@types/node": "^24.12.4",
40
+ "@rslib/core": "0.23.1",
41
+ "@types/node": "^24.13.2",
34
42
  "svgo": "^3.3.3",
35
43
  "typescript": "^6.0.3",
36
- "@rsbuild/core": "2.0.9",
44
+ "@rsbuild/core": "2.1.2",
37
45
  "@scripts/test-helper": "1.0.0"
38
46
  },
39
47
  "peerDependencies": {
40
- "@rsbuild/core": "^2.0.0-0"
48
+ "@rsbuild/core": "^2.0.0"
41
49
  },
42
50
  "peerDependenciesMeta": {
43
51
  "@rsbuild/core": {
44
52
  "optional": true
45
53
  }
46
54
  },
47
- "publishConfig": {
48
- "access": "public",
49
- "registry": "https://registry.npmjs.org/"
50
- },
51
55
  "scripts": {
52
56
  "build": "rslib",
53
57
  "dev": "rslib -w"