react-icons-sprite 0.7.1 → 0.8.0-rc.0

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.
@@ -0,0 +1,5 @@
1
+ import { r as createCollector } from "./core-02H9qSgn.mjs";
2
+ //#region src/collector.ts
3
+ const collector = createCollector();
4
+ //#endregion
5
+ export { collector as t };
@@ -4,7 +4,6 @@ import * as t from "@babel/types";
4
4
  import { parse } from "@babel/parser";
5
5
  import _traverse from "@babel/traverse";
6
6
  import _generate from "@babel/generator";
7
-
8
7
  //#region src/core.ts
9
8
  const traverse = _traverse.default ?? _traverse;
10
9
  const generate = _generate.default ?? _generate;
@@ -25,8 +24,7 @@ const DEFAULT_ICON_SOURCES = [
25
24
  /^devicons-react$/,
26
25
  /^@fortawesome\/react-fontawesome$/,
27
26
  /^@fortawesome\/[\w-]+-svg-icons$/,
28
- /^@mui\/icons-material(?:\/.*)?$/,
29
- /^@iconscout\/react-unicons$/
27
+ /^@mui\/icons-material(?:\/.*)?$/
30
28
  ];
31
29
  const sourceMatchesSupported = (source, sources = DEFAULT_ICON_SOURCES) => sources.some((re) => re.test(source));
32
30
  const normalizeAlias = (pack) => {
@@ -71,8 +69,8 @@ const collectIconImports = (ast, sources = DEFAULT_ICON_SOURCES) => {
71
69
  const findExistingIconImport = (ast) => {
72
70
  let iconLocalName = ICON_COMPONENT_NAME;
73
71
  let hasIconImport = false;
74
- for (const n of ast.program.body) if (t.isImportDeclaration(n) && n.source.value === ICON_SOURCE) {
75
- for (const s of n.specifiers) if (t.isImportSpecifier(s) && t.isIdentifier(s.imported, { name: ICON_COMPONENT_NAME })) {
72
+ for (const n of ast.program.body) if (t.isImportDeclaration(n) && n.source.value === "react-icons-sprite") {
73
+ for (const s of n.specifiers) if (t.isImportSpecifier(s) && t.isIdentifier(s.imported, { name: "ReactIconsSpriteIcon" })) {
76
74
  hasIconImport = true;
77
75
  iconLocalName = t.isIdentifier(s.local) ? s.local.name : ICON_COMPONENT_NAME;
78
76
  break;
@@ -281,6 +279,5 @@ const createCollector = () => {
281
279
  }
282
280
  };
283
281
  };
284
-
285
282
  //#endregion
286
- export { transformModule as i, buildSprite as n, createCollector as r, DEFAULT_ICON_SOURCES as t };
283
+ export { transformModule as i, buildSprite as n, createCollector as r, DEFAULT_ICON_SOURCES as t };
package/dist/icon.mjs CHANGED
@@ -1,5 +1,4 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
-
3
2
  //#region src/icon.tsx
4
3
  const ReactIconsSpriteIcon = ({ iconId, ...rest }) => {
5
4
  const iconHref = `__SPRITE_URL_PLACEHOLDER__#${iconId}`;
@@ -12,6 +11,5 @@ const ReactIconsSpriteIcon = ({ iconId, ...rest }) => {
12
11
  children: /* @__PURE__ */ jsx("use", { href: iconHref })
13
12
  });
14
13
  };
15
-
16
14
  //#endregion
17
- export { ReactIconsSpriteIcon };
15
+ export { ReactIconsSpriteIcon };
package/dist/index.mjs CHANGED
@@ -1,7 +1,5 @@
1
1
  import { ReactIconsSpriteIcon } from "./icon.mjs";
2
-
3
2
  //#region src/index.ts
4
3
  const REACT_ICONS_SPRITE_URL_PLACEHOLDER = "__SPRITE_URL_PLACEHOLDER__";
5
-
6
4
  //#endregion
7
- export { REACT_ICONS_SPRITE_URL_PLACEHOLDER, ReactIconsSpriteIcon };
5
+ export { REACT_ICONS_SPRITE_URL_PLACEHOLDER, ReactIconsSpriteIcon };
@@ -1,7 +1,6 @@
1
1
  import { REACT_ICONS_SPRITE_URL_PLACEHOLDER } from "../index.mjs";
2
- import { i as transformModule, n as buildSprite, r as createCollector, t as DEFAULT_ICON_SOURCES } from "../core-Di2t0EYk.mjs";
2
+ import { i as transformModule, n as buildSprite, r as createCollector, t as DEFAULT_ICON_SOURCES } from "../core-02H9qSgn.mjs";
3
3
  import { createHash } from "node:crypto";
4
-
5
4
  //#region src/vite/plugin.ts
6
5
  const reactIconsSprite = (options = {}) => {
7
6
  const { fileName } = options;
@@ -41,11 +40,10 @@ const reactIconsSprite = (options = {}) => {
41
40
  const assetId = this.emitFile(emitFileOptions);
42
41
  const finalUrl = `/${this.getFileName(assetId)}`;
43
42
  for (const [, item] of Object.entries(bundle)) if (item.type === "chunk" && typeof item.code === "string") {
44
- if (item.code.includes(REACT_ICONS_SPRITE_URL_PLACEHOLDER)) item.code = item.code.replaceAll(REACT_ICONS_SPRITE_URL_PLACEHOLDER, finalUrl);
43
+ if (item.code.includes("__SPRITE_URL_PLACEHOLDER__")) item.code = item.code.replaceAll(REACT_ICONS_SPRITE_URL_PLACEHOLDER, finalUrl);
45
44
  }
46
45
  }
47
46
  };
48
47
  };
49
-
50
48
  //#endregion
51
- export { reactIconsSprite };
49
+ export { reactIconsSprite };
@@ -1,11 +1,11 @@
1
- import { i as transformModule } from "../core-Di2t0EYk.mjs";
2
- import { t as collector } from "../collector-BCsSIe1N.mjs";
3
-
1
+ import { i as transformModule } from "../core-02H9qSgn.mjs";
2
+ import { t as collector } from "../collector-D3-6hdBe.mjs";
4
3
  //#region src/webpack/loader.ts
5
4
  const reactIconsSpriteLoader = async function(source) {
5
+ if (this.mode === "development") return source;
6
6
  const id = this.resourcePath;
7
7
  try {
8
- if (!/\.(mjs|cjs|js|jsx|ts|tsx)$/i.test(id) || !/from\s+['"]react-icons\//.test(String(source))) return source;
8
+ if (!/\.(mjs|cjs|js|jsx|ts|tsx)$/i.test(id)) return source;
9
9
  const { code, anyReplacements } = transformModule(String(source), id, (pack, exportName) => {
10
10
  collector.add(pack, exportName);
11
11
  });
@@ -16,6 +16,5 @@ const reactIconsSpriteLoader = async function(source) {
16
16
  return source;
17
17
  }
18
18
  };
19
-
20
19
  //#endregion
21
- export { reactIconsSpriteLoader as default };
20
+ export { reactIconsSpriteLoader as default };
@@ -1,8 +1,7 @@
1
1
  import { REACT_ICONS_SPRITE_URL_PLACEHOLDER } from "../index.mjs";
2
- import { n as buildSprite } from "../core-Di2t0EYk.mjs";
3
- import { t as collector } from "../collector-BCsSIe1N.mjs";
2
+ import { n as buildSprite } from "../core-02H9qSgn.mjs";
3
+ import { t as collector } from "../collector-D3-6hdBe.mjs";
4
4
  import { createHash } from "node:crypto";
5
-
6
5
  //#region src/webpack/plugin.ts
7
6
  var ReactIconsSpriteWebpackPlugin = class {
8
7
  fileName;
@@ -10,6 +9,7 @@ var ReactIconsSpriteWebpackPlugin = class {
10
9
  this.fileName = options.fileName;
11
10
  }
12
11
  apply(compiler) {
12
+ if (compiler.options.mode === "development") return;
13
13
  const pluginName = "react-icons-sprite-webpack-plugin";
14
14
  compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
15
15
  collector.clear();
@@ -34,7 +34,7 @@ var ReactIconsSpriteWebpackPlugin = class {
34
34
  if (!/\.(js|mjs|cjs)$/i.test(filename)) continue;
35
35
  const src = asset.source.source();
36
36
  if (typeof src !== "string") continue;
37
- if (!src.includes(REACT_ICONS_SPRITE_URL_PLACEHOLDER)) continue;
37
+ if (!src.includes("__SPRITE_URL_PLACEHOLDER__")) continue;
38
38
  const next = src.replaceAll(REACT_ICONS_SPRITE_URL_PLACEHOLDER, finalUrl);
39
39
  compilation.updateAsset(filename, new RawSource(next));
40
40
  }
@@ -42,6 +42,5 @@ var ReactIconsSpriteWebpackPlugin = class {
42
42
  });
43
43
  }
44
44
  };
45
-
46
45
  //#endregion
47
- export { ReactIconsSpriteWebpackPlugin };
46
+ export { ReactIconsSpriteWebpackPlugin };
package/package.json CHANGED
@@ -1,29 +1,31 @@
1
1
  {
2
2
  "name": "react-icons-sprite",
3
- "version": "0.7.1",
3
+ "version": "0.8.0-rc.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "",
7
7
  "author": "Jure Rotar <hello@jurerotar.com>",
8
8
  "homepage": "https://github.com/jurerotar/react-icons-sprite#README",
9
- "main": "dist/icon.mjs",
10
- "types": "dist/icon.d.mts",
9
+ "main": "dist/index.mjs",
10
+ "module": "dist/index.mjs",
11
+ "types": "dist/index.d.mts",
11
12
  "sideEffects": false,
12
13
  "exports": {
13
14
  ".": {
14
15
  "types": "./dist/index.d.mts",
15
- "import": "./dist/index.mjs",
16
- "default": "./dist/index.mjs"
16
+ "import": "./dist/index.mjs"
17
+ },
18
+ "./icon": {
19
+ "types": "./dist/icon.d.mts",
20
+ "import": "./dist/icon.mjs"
17
21
  },
18
22
  "./vite": {
19
23
  "types": "./dist/vite/plugin.d.mts",
20
- "import": "./dist/vite/plugin.mjs",
21
- "default": "./dist/vite/plugin.mjs"
24
+ "import": "./dist/vite/plugin.mjs"
22
25
  },
23
26
  "./webpack": {
24
27
  "types": "./dist/webpack/plugin.d.mts",
25
- "import": "./dist/webpack/plugin.mjs",
26
- "default": "./dist/webpack/plugin.mjs"
28
+ "import": "./dist/webpack/plugin.mjs"
27
29
  },
28
30
  "./webpack/loader": {
29
31
  "types": "./dist/webpack/loader.d.mts",
@@ -47,10 +49,10 @@
47
49
  "scripts": {
48
50
  "build": "tsdown",
49
51
  "dev": "tsdown --watch",
50
- "format:check": "biome format --no-errors-on-unmatched",
51
52
  "format": "biome format --write --no-errors-on-unmatched",
52
- "lint:check": "biome lint --no-errors-on-unmatched",
53
+ "format:check": "biome format --no-errors-on-unmatched",
53
54
  "lint": "biome lint --write --no-errors-on-unmatched",
55
+ "lint:check": "biome lint --no-errors-on-unmatched",
54
56
  "type-check": "tsgo",
55
57
  "test": "vitest run",
56
58
  "prepublishOnly": "npm run build",
@@ -67,43 +69,27 @@
67
69
  "@babel/types": "7.29.0"
68
70
  },
69
71
  "devDependencies": {
70
- "@biomejs/biome": "2.3.14",
71
- "@emotion/react": "11.14.0",
72
- "@emotion/styled": "11.14.1",
73
- "@fortawesome/free-solid-svg-icons": "7.2.0",
74
- "@fortawesome/react-fontawesome": "3.2.0",
75
- "@heroicons/react": "2.2.0",
76
- "@iconscout/react-unicons": "2.2.5",
77
- "@mui/icons-material": "7.3.7",
78
- "@phosphor-icons/react": "2.1.10",
79
- "@radix-ui/react-icons": "1.3.2",
80
- "@remixicon/react": "4.9.0",
81
- "@tabler/icons-react": "3.36.1",
82
72
  "@types/babel__generator": "7.27.0",
83
73
  "@types/babel__traverse": "7.28.0",
84
- "@types/node": "25.2.3",
74
+ "@types/node": "25.3.5",
85
75
  "@types/react-dom": "19.2.3",
86
- "@typescript/native-preview": "7.0.0-dev.20260211.1",
87
- "devicons-react": "1.5.0",
88
- "grommet-icons": "4.14.0",
89
- "lucide-react": "0.563.0",
90
- "phosphor-react": "1.4.1",
76
+ "@typescript/native-preview": "7.0.0-dev.20260309.1",
91
77
  "react": "19.2.4",
92
- "react-bootstrap-icons": "1.11.6",
93
78
  "react-dom": "19.2.4",
94
- "react-feather": "2.0.10",
95
- "react-icons": "5.5.0",
96
- "tsdown": "0.20.3",
79
+ "tsdown": "0.21.1",
97
80
  "typescript": "5.9.3",
98
81
  "vite": "7.3.1",
99
82
  "vitest": "4.0.18",
100
- "webpack": "5.105.1"
83
+ "webpack": "5.105.4"
101
84
  },
102
85
  "keywords": [
103
86
  "vite",
104
87
  "vite-plugin",
105
88
  "webpack",
106
89
  "webpack-plugin",
90
+ "rsbuild",
91
+ "rsbuild-plugin",
92
+ "esbuild",
107
93
  "rollup",
108
94
  "rolldown",
109
95
  "react-icons",
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright © 2025 Jure Rotar
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE
package/README.md DELETED
@@ -1,209 +0,0 @@
1
- # react-icons-sprite
2
-
3
- `react-icons-sprite` is a lightweight plugin for Vite and Webpack that turns React icon components into a single SVG spritesheet and rewrites your code to reference those symbols via `<use>`.
4
-
5
- It supports multiple React icon packages that export icons as individual React components. This approach both shrinks your bundle (no more inlined React components for every icon) and reduces runtime overhead, since React no longer has to reconcile large, nested SVG trees.
6
-
7
- ## Supported icon libraries
8
-
9
- Out of the box, imports from the following libraries are detected and transformed:
10
-
11
- - `react-icons/*` packs (e.g. `react-icons/bi`, `react-icons/fa`, ...)
12
- - `lucide-react`
13
- - `@radix-ui/react-icons`
14
- - `@heroicons/react` (v1 and v2 subpaths)
15
- - `@tabler/icons-react`
16
- - `phosphor-react`
17
- - `@phosphor-icons/react`
18
- - `react-feather`
19
- - `react-bootstrap-icons`
20
- - `grommet-icons`
21
- - `@remixicon/react`
22
- - `devicons-react`
23
- - `@fortawesome/free-solid-svg-icons` (and other Font Awesome icon packs)
24
- - `@fortawesome/react-fontawesome`
25
- - `@mui/icons-material`
26
-
27
- > [!NOTE]
28
- > `react-icons-sprite` does not bundle these libraries. You must install whichever icon packages you intend to use in your project.
29
-
30
- ## Motivation
31
-
32
- By default, when you use an icon library like `react-icons`, each icon is a React component. For example:
33
-
34
- ```tsx
35
- import { LuWheat } from "react-icons/lu";
36
-
37
- export function Example() {
38
- return <LuWheat />;
39
- }
40
- ```
41
-
42
- looks harmless, but at build time this compiles to something like:
43
-
44
- ```javascript
45
- import { b as e } from './iconBase-BU3rGdXB.js'
46
-
47
- function t(t) {
48
- return e({
49
- tag: `svg`, attr: { viewBox: `0 0 640 512` }, child: [{
50
- tag: `path`, attr: {
51
- d: `M524.531,69.836a1.5,1.5,0,0,0-.764-.7A485.065,485.065,0,0,0,404.081,32.03a1.816,1.816,0,0,0-1.923.91,337.461,337.461,0,0,0-14.9,30.6,447.848,447.848,0,0,0-134.426,0,309.541,309.541,0,0,0-15.135-30.6,1.89,1.89,0,0,0-1.924-.91A483.689,483.689,0,0,0,116.085,69.137a1.712,1.712,0,0,0-.788.676C39.068,183.651,18.186,294.69,28.43,404.354a2.016,2.016,0,0,0,.765,1.375A487.666,487.666,0,0,0,176.02,479.918a1.9,1.9,0,0,0,2.063-.676A348.2,348.2,0,0,0,208.12,430.4a1.86,1.86,0,0,0-1.019-2.588,321.173,321.173,0,0,1-45.868-21.853,1.885,1.885,0,0,1-.185-3.126c3.082-2.309,6.166-4.711,9.109-7.137a1.819,1.819,0,0,1,1.9-.256c96.229,43.917,200.41,43.917,295.5,0a1.812,1.812,0,0,1,1.924.233c2.944,2.426,6.027,4.851,9.132,7.16a1.884,1.884,0,0,1-.162,3.126,301.407,301.407,0,0,1-45.89,21.83,1.875,1.875,0,0,0-1,2.611,391.055,391.055,0,0,0,30.014,48.815,1.864,1.864,0,0,0,2.063.7A486.048,486.048,0,0,0,610.7,405.729a1.882,1.882,0,0,0,.765-1.352C623.729,277.594,590.933,167.465,524.531,69.836ZM222.491,337.58c-28.972,0-52.844-26.587-52.844-59.239S193.056,219.1,222.491,219.1c29.665,0,53.306,26.82,52.843,59.239C275.334,310.993,251.924,337.58,222.491,337.58Zm195.38,0c-28.971,0-52.843-26.587-52.843-59.239S388.437,219.1,417.871,219.1c29.667,0,53.307,26.82,52.844,59.239C470.715,310.993,447.538,337.58,417.871,337.58Z`
52
- }, child: []
53
- }]
54
- })(t)
55
- }
56
-
57
- function n(t) {
58
- return e({
59
- tag: `svg`, attr: { viewBox: `0 0 496 512` }, child: [{
60
- tag: `path`, attr: {
61
- d: `M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z`
62
- }, child: []
63
- }]
64
- })(t)
65
- }
66
-
67
- // ... potentially dozens more child components.
68
-
69
- export { t, n };
70
- ```
71
-
72
- That means:
73
-
74
- - Every icon adds hundreds of characters of JSX to your bundle.
75
- - At runtime, React must create and diff dozens of DOM nodes for every icon render.
76
- - If you render 100 icons, React is reconciling potentially thousands of <path> elements.
77
-
78
- Now compare that to output when using a spritesheet with `<use>`:
79
-
80
- ```tsx
81
- import { LuWheat } from "react-icons/lu";
82
-
83
- export function Example() {
84
- return <LuWheat />;
85
- }
86
- ```
87
-
88
- ```javascript
89
- import { b as n } from './icon-FONPSuqX.js';
90
-
91
- var r = e(t());
92
- const i = () => (0, r.jsx)(n, { iconId: `ri-react-icons-lu-LuWheat` });
93
- export { i as IconWheat };
94
- ```
95
-
96
- `icon-FONPSuqX.js` in this case is our simple icon wrapper, which looks like this:
97
-
98
- ```javascript
99
- var n = e(t());
100
- const r = ({ iconId: e, ...t }) => {
101
- let r = `assets/react-icons-sprite-C-JClopV.svg#${e}`;
102
- return (0, n.jsxs)(`svg`, {
103
- height: `1em`,
104
- width: `1em`,
105
- preserveAspectRatio: `xMidYMid meet`,
106
- viewBox: `0 0 24 24`, ...t,
107
- children: [(0, n.jsx)(`title`, { children: e }), (0, n.jsx)(`use`, { href: r })]
108
- })
109
- };
110
- export { r as b };
111
- ```
112
-
113
- Runtime difference:
114
-
115
- - React only reconciles two DOM nodes (`<svg>` + `<use>`).
116
- - All heavy path data lives in the static spritesheet once, not duplicated across components.
117
- - Updating 100 icons is as cheap as updating 100 `<use>` tags.
118
-
119
- This is a big win when you’re rendering icons in lists, tables, or maps where dozens or hundreds of them appear at once.
120
-
121
- ### Performance comparison
122
-
123
- | icon (pack) | react-icons icon render mean time | react-icons-sprite icon render mean time | Relative difference |
124
- |--------------------|----------------------------------:|---------------------------------------------:|------------------------:|
125
- | **FiCpu** (fi) | 0.188 ms | 0.048 ms | 74.6% reduction |
126
- | **MdBuild** (md) | 0.198 ms | 0.048 ms | 76.0% reduction |
127
- | **FaCamera** (fa) | 0.162 ms | 0.015 ms | 90.7% reduction |
128
- | **IoAperture** (io5)| 0.029 ms | 0.015 ms | 49.7% reduction |
129
- | **BiBell** (bi) | 0.023 ms | 0.014 ms | 38.5% reduction |
130
- | **AiOutlineAlert** (ai) | 0.023 ms | 0.014 ms | 38.3% reduction |
131
- | **BsAlarm** (bs) | 0.027 ms | 0.014 ms | 47.4% reduction |
132
- | **RiAnchor** (ri) | 0.023 ms | 0.014 ms | 38.6% reduction |
133
- | **CgArrows** (cg) | 0.029 ms | 0.014 ms | 52.0% reduction |
134
- | **HiAcademicCap** (hi) | 0.023 ms | 0.014 ms | 38.6% reduction |
135
- | **SiTypescript** (si) | 0.023 ms | 0.014 ms | 39.7% reduction |
136
- | **TiThLarge** (ti) | 0.023 ms | 0.014 ms | 40.0% reduction |
137
-
138
- * **Test details / machine:** **Lenovo Legion 5 Pro 16ACH6H** (Ryzen 7 5800H — 8 cores / 16 threads, base ≈ 3.2 GHz, turbo ≈ 4.4 GHz, DDR4-3200 memory); Node.js v24.10.0.
139
- * Differences will vary based on icons used in your application, but they will generally be the range of 50-75% reduction in render time. Larger icons will generate a larger difference.
140
-
141
- ## Installation
142
-
143
- Install the plugin via npm or yarn:
144
-
145
- ```bash
146
- npm install --save-dev react-icons-sprite
147
- ```
148
-
149
- ### Vite
150
- Add the plugin to the `plugins` array in your Vite config.
151
-
152
- ```typescript
153
- // vite.config.ts
154
- import { defineConfig } from 'vite';
155
- import { reactIconsSprite } from 'react-icons-sprite/vite';
156
-
157
- export default defineConfig({
158
- plugins: [reactIconsSprite()],
159
- });
160
- ```
161
-
162
- ### Webpack
163
- Add the loader to transform modules that import icons and install the plugin to emit the sprite and rewrite the placeholder URL.
164
-
165
- ```js
166
- // webpack.config.js (v5)
167
- const path = require('path');
168
- const { reactIconsSprite } = require('react-icons-sprite/webpack');
169
-
170
- module.exports = {
171
- mode: 'production',
172
- // ... your existing config
173
- module: {
174
- rules: [
175
- {
176
- test: /\.(mjs|cjs|js|jsx|ts|tsx)$/,
177
- exclude: /node_modules/,
178
- use: [
179
- {
180
- loader: require.resolve('react-icons-sprite/webpack/loader'),
181
- },
182
- // put your ts/tsx loader after ours (e.g. babel-loader or ts-loader)
183
- ],
184
- },
185
- ],
186
- },
187
- plugins: [
188
- reactIconsSprite({
189
- // optional: fileName: 'icons.svg'
190
- }),
191
- ],
192
- };
193
- ```
194
-
195
- ## How it works
196
-
197
- In **development mode**, the plugin does nothing special. Icons are rendered as they normally would from your icon library. This keeps hot module replacement (HMR) snappy — there’s no extra parsing of the codebase or regenerating of the sprite on every save. If the plugin were to build the sprite during dev, it would need to constantly scan for icon imports and rebuild the sheet, which is expensive and slows down iteration. So, in dev, you get the normal component behavior.
198
-
199
- In **build mode**, the plugin transforms your code. It parses each module, looks for imports from supported React icon packages, and rewrites the JSX. Instead of rendering full inline `<svg>` trees, it replaces them with `<ReactIconsSpriteIcon iconId="..." />`. While doing this, it collects every unique icon used across the project. After the bundling step, the plugin renders all those icons once to static markup and generates a single SVG file containing `<symbol>` definitions for each one. Finally, it rewrites your bundle to point every `<ReactIconsSpriteIcon>` at that spritesheet using a `<use>` tag.
200
-
201
- The result: during development you keep fast feedback loops, and in production you ship a single optimized sprite file with lightweight `<use>` references.
202
-
203
- ## Contributing
204
-
205
- Contributions are welcome! Feel free to open an issue or submit a pull request.
206
-
207
- ## License
208
-
209
- This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
@@ -1,7 +0,0 @@
1
- import { r as createCollector } from "./core-Di2t0EYk.mjs";
2
-
3
- //#region src/collector.ts
4
- const collector = createCollector();
5
-
6
- //#endregion
7
- export { collector as t };