@rsbuild/plugin-svgr 2.0.3 → 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 CHANGED
@@ -21,6 +21,14 @@ export type PluginSvgrOptions = {
21
21
  * @default /react/
22
22
  */ query?: RegExp;
23
23
  /**
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;
31
+ /**
24
32
  * Exclude specific SVG files from SVGR transformation.
25
33
  */ exclude?: Rspack.RuleSetCondition;
26
34
  /**
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,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$/), 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_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
- }).end();
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), svgRule.type("javascript/auto").set('issuer', issuer).use(CHAIN_ID.USE.SVGR).loader(node_path.join(import.meta.dirname, 'loader.mjs')).options({
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
- }).end(), mixedImport && 'named' === exportType && svgRule.use(CHAIN_ID.USE.URL).loader(node_path.join(import.meta.dirname, 'assetLoader.mjs')).options({
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",
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
- "license": "MIT",
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
- "types": "./dist/index.d.ts",
19
- "files": [
20
- "dist"
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.22.0",
33
- "@types/node": "^24.12.4",
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.9",
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-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"