Skip to content

Commit 5d7357b

Browse files
committed
feat: update build icon wrapper
1 parent 39b674e commit 5d7357b

File tree

1,620 files changed

+32920
-33915
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,620 files changed

+32920
-33915
lines changed

README.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ This runs the full pipeline:
148148
| `scan-icons.js` | Parse your codebase for used icons (`Icon` usage or named imports) |
149149
| `used-icons.js` | Collects a list of unique icon names |
150150
| `build-sprite.js` | Uses [`svgstore`](https://github.com/DIYgod/svgstore) to generate `icons.svg` from used Lucide + custom SVGs |
151-
| `config.js` | Loads your `zero-ui.config.js` if present |
152151

153152

154153
---
@@ -159,20 +158,6 @@ This runs the full pipeline:
159158
* **Only ships the icons you actually use** — smallest possible sprite.
160159
* **Minimal install**: No runtime dependency tree. Just React + Lucide.
161160

162-
---
163-
164-
## 🔧 Configuration (`zero-ui.config.js`)
165-
166-
You can override defaults with a root config file:
167-
168-
```ts
169-
// zero-ui.config.js
170-
export default {
171-
ROOT_DIR: "src", // where to scan for custom icon usage (default: "")
172-
SPRITE_PATH: "icons.svg", // emitted to /public/icons.svg
173-
CUSTOM_SVG_DIR: "zero-ui-icons", // folder for your custom SVGs at project root
174-
}
175-
```
176161

177162
---
178163

icon-sprite/README.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ This runs the full pipeline:
148148
| `scan-icons.js` | Parse your codebase for used icons (`Icon` usage or named imports) |
149149
| `used-icons.js` | Collects a list of unique icon names |
150150
| `build-sprite.js` | Uses [`svgstore`](https://github.com/DIYgod/svgstore) to generate `icons.svg` from used Lucide + custom SVGs |
151-
| `config.js` | Loads your `zero-ui.config.js` if present |
152-
151+
153152

154153
---
155154
## ✨ Why This Is Better
@@ -159,20 +158,6 @@ This runs the full pipeline:
159158
* **Only ships the icons you actually use** — smallest possible sprite.
160159
* **Minimal install**: No runtime dependency tree. Just React + Lucide.
161160

162-
---
163-
164-
## 🔧 Configuration (`zero-ui.config.js`)
165-
166-
You can override defaults with a root config file:
167-
168-
```ts
169-
// zero-ui.config.js
170-
export default {
171-
ROOT_DIR: "src", // where to scan for custom icon usage (default: "")
172-
SPRITE_PATH: "icons.svg", // emitted to /public/icons.svg
173-
CUSTOM_SVG_DIR: "zero-ui-icons", // folder for your custom SVGs at project root
174-
}
175-
```
176161

177162
---
178163

icon-sprite/scripts/gen-wrappers.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,31 @@ for (const file of files) {
2626
const id = file.replace(".svg", ""); // e.g. "arrow-right"
2727
const pascal = toPascal(id); // "ArrowRight"
2828
const wrapperTsx = `\
29-
import { ${pascal} as DevIcon, type LucideProps } from "lucide-react"
3029
import { SPRITE_PATH } from "../config.js";
3130
import { warnMissingIconSize } from "../utils.js";
31+
import { createRequire } from "module";
32+
import { renderUse,type IconProps,} from "../_shared.js";
33+
34+
let DevIcon: ((p: IconProps) => React.JSX.Element) | undefined;
35+
if (process.env.NODE_ENV !== "production") {
36+
const require = createRequire(import.meta.url);
37+
const mod = require("lucide-react");
38+
DevIcon = mod.${pascal} as any;
39+
}
3240
33-
interface Props extends LucideProps { size?: number | string | undefined; width?: number | string | undefined; height?: number | string | undefined; }
34-
35-
export function ${pascal}({ size, width, height, ...props }: Props) {
41+
export function ${pascal}({ size, width, height, ...props }: IconProps) {
3642
warnMissingIconSize("${pascal}", size, width, height);
37-
38-
return process.env.NODE_ENV !== "production" ? (
39-
<DevIcon
40-
{...props}
41-
{...(size != null ? { size } : {})}
42-
{...(width != null ? { width } : {})}
43-
{...(height != null ? { height } : {})}
44-
/>
45-
) : (
46-
<svg
47-
{...props}
48-
{...(size != null ? { width: size, height: size } : {})}
49-
{...(width != null ? { width } : {})}
50-
{...(height != null ? { height } : {})}
51-
>
52-
<use href={\`\${SPRITE_PATH}#${id}\`} />
53-
</svg>
54-
);
43+
if (process.env.NODE_ENV !== "production" && DevIcon) {
44+
return (
45+
<DevIcon
46+
{...(props as any)}
47+
{...(size != null ? { size } : {})}
48+
{...(width != null ? { width } : {})}
49+
{...(height != null ? { height } : {})}
50+
/>
51+
);
52+
}
53+
return renderUse("${id}", width, height, size, SPRITE_PATH, props)
5554
}
5655
`;
5756

icon-sprite/scripts/scan-icons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
1212
const ICONS = new Set();
1313

1414
// 1️⃣ Find the consuming app's root
15-
export function findProjectRoot(dir = process.cwd()) {
15+
function findProjectRoot(dir = process.cwd()) {
1616
let current = dir;
1717
while (true) {
1818
if (fs.existsSync(path.join(current, "package.json"))) return current;

icon-sprite/src/_shared.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export type Dim = number | string | undefined;
2+
export type IconProps = React.SVGProps<SVGSVGElement> & { size?: Dim; width?: Dim; height?: Dim };
3+
export function renderUse(id: string, width: Dim, height: Dim, size: Dim, SPRITE_PATH: string, props: IconProps) {
4+
return (
5+
<svg
6+
{...props}
7+
{...(size != null ? { width: size, height: size } : {})}
8+
{...(width != null ? { width } : {})}
9+
{...(height != null ? { height } : {})}
10+
>
11+
<use href={`${SPRITE_PATH}#${id}`} />
12+
</svg>
13+
);
14+
}

icon-sprite/src/config.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
11
// src/config.ts
2-
import fs from "fs";
3-
import path from "path";
4-
import { pathToFileURL } from "url";
2+
// import fs from "fs";
3+
// import path from "path";
4+
// import { pathToFileURL } from "url";
55

6-
const DEFAULT_CONFIG = {
7-
IMPORT_NAME: "@react-zero-ui/icon-sprite",
8-
SPRITE_PATH: "/icons.svg",
9-
ROOT_DIR: "",
10-
CUSTOM_SVG_DIR: "zero-ui-icons",
11-
OUTPUT_DIR: "public",
12-
IGNORE_ICONS: ["CustomIcon"],
13-
};
6+
// const DEFAULT_CONFIG = {
7+
// IMPORT_NAME: "@react-zero-ui/icon-sprite",
8+
// SPRITE_PATH: "/icons.svg",
9+
// ROOT_DIR: "",
10+
// CUSTOM_SVG_DIR: "zero-ui-icons",
11+
// OUTPUT_DIR: "public",
12+
// IGNORE_ICONS: ["CustomIcon"],
13+
// };
1414

15-
let userConfig = {};
16-
const configFile = path.resolve(process.cwd(), "zero-ui.config.js");
15+
// let userConfig = {};
16+
// const configFile = path.resolve(process.cwd(), "zero-ui.config.js");
1717

18-
if (fs.existsSync(configFile)) {
19-
try {
20-
const mod = await import(pathToFileURL(configFile).href);
21-
userConfig = mod.default ?? mod;
22-
} catch (e) {
23-
// @ts-expect-error
24-
console.warn("⚠️ Failed to load zero-ui.config.js:", e.message);
25-
}
26-
}
18+
// if (fs.existsSync(configFile)) {
19+
// try {
20+
// const mod = await import(pathToFileURL(configFile).href);
21+
// userConfig = mod.default ?? mod;
22+
// } catch (e) {
23+
// // @ts-expect-error
24+
// console.warn("⚠️ Failed to load zero-ui.config.js:", e.message);
25+
// }
26+
// }
2727

28-
const merged = { ...DEFAULT_CONFIG, ...userConfig };
28+
// const merged = { ...DEFAULT_CONFIG, ...userConfig };
2929

30-
export const IMPORT_NAME = merged.IMPORT_NAME;
31-
export const SPRITE_PATH = merged.SPRITE_PATH;
32-
export const ROOT_DIR = merged.ROOT_DIR;
33-
export const CUSTOM_SVG_DIR = merged.CUSTOM_SVG_DIR;
34-
export const OUTPUT_DIR = merged.OUTPUT_DIR;
35-
export const IGNORE_ICONS = merged.IGNORE_ICONS;
30+
// export const IMPORT_NAME = merged.IMPORT_NAME;
31+
// export const SPRITE_PATH = merged.SPRITE_PATH;
32+
// export const ROOT_DIR = merged.ROOT_DIR;
33+
// export const CUSTOM_SVG_DIR = merged.CUSTOM_SVG_DIR;
34+
// export const OUTPUT_DIR = merged.OUTPUT_DIR;
35+
// export const IGNORE_ICONS = merged.IGNORE_ICONS;
36+
37+
export const IMPORT_NAME = "@react-zero-ui/icon-sprite";
38+
export const SPRITE_PATH = "/icons.svg";
39+
export const ROOT_DIR = "";
40+
export const CUSTOM_SVG_DIR = "zero-ui-icons";
41+
export const OUTPUT_DIR = "public";
42+
export const IGNORE_ICONS = ["CustomIcon"];
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
import { AArrowDown as DevIcon, type LucideProps } from "lucide-react"
21
import { SPRITE_PATH } from "../config.js";
32
import { warnMissingIconSize } from "../utils.js";
3+
import { createRequire } from "module";
4+
import { renderUse,type IconProps,} from "../_shared.js";
45

5-
interface Props extends LucideProps { size?: number | string | undefined; width?: number | string | undefined; height?: number | string | undefined; }
6+
let DevIcon: ((p: IconProps) => React.JSX.Element) | undefined;
7+
if (process.env.NODE_ENV !== "production") {
8+
const require = createRequire(import.meta.url);
9+
const mod = require("lucide-react");
10+
DevIcon = mod.AArrowDown as any;
11+
}
612

7-
export function AArrowDown({ size, width, height, ...props }: Props) {
13+
export function AArrowDown({ size, width, height, ...props }: IconProps) {
814
warnMissingIconSize("AArrowDown", size, width, height);
9-
10-
return process.env.NODE_ENV !== "production" ? (
11-
<DevIcon
12-
{...props}
13-
{...(size != null ? { size } : {})}
14-
{...(width != null ? { width } : {})}
15-
{...(height != null ? { height } : {})}
16-
/>
17-
) : (
18-
<svg
19-
{...props}
20-
{...(size != null ? { width: size, height: size } : {})}
21-
{...(width != null ? { width } : {})}
22-
{...(height != null ? { height } : {})}
23-
>
24-
<use href={`${SPRITE_PATH}#a-arrow-down`} />
25-
</svg>
26-
);
15+
if (process.env.NODE_ENV !== "production" && DevIcon) {
16+
return (
17+
<DevIcon
18+
{...(props as any)}
19+
{...(size != null ? { size } : {})}
20+
{...(width != null ? { width } : {})}
21+
{...(height != null ? { height } : {})}
22+
/>
23+
);
24+
}
25+
return renderUse("a-arrow-down", width, height, size, SPRITE_PATH, props)
2726
}

icon-sprite/src/icons/AArrowUp.tsx

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
import { AArrowUp as DevIcon, type LucideProps } from "lucide-react"
21
import { SPRITE_PATH } from "../config.js";
32
import { warnMissingIconSize } from "../utils.js";
3+
import { createRequire } from "module";
4+
import { renderUse,type IconProps,} from "../_shared.js";
45

5-
interface Props extends LucideProps { size?: number | string | undefined; width?: number | string | undefined; height?: number | string | undefined; }
6+
let DevIcon: ((p: IconProps) => React.JSX.Element) | undefined;
7+
if (process.env.NODE_ENV !== "production") {
8+
const require = createRequire(import.meta.url);
9+
const mod = require("lucide-react");
10+
DevIcon = mod.AArrowUp as any;
11+
}
612

7-
export function AArrowUp({ size, width, height, ...props }: Props) {
13+
export function AArrowUp({ size, width, height, ...props }: IconProps) {
814
warnMissingIconSize("AArrowUp", size, width, height);
9-
10-
return process.env.NODE_ENV !== "production" ? (
11-
<DevIcon
12-
{...props}
13-
{...(size != null ? { size } : {})}
14-
{...(width != null ? { width } : {})}
15-
{...(height != null ? { height } : {})}
16-
/>
17-
) : (
18-
<svg
19-
{...props}
20-
{...(size != null ? { width: size, height: size } : {})}
21-
{...(width != null ? { width } : {})}
22-
{...(height != null ? { height } : {})}
23-
>
24-
<use href={`${SPRITE_PATH}#a-arrow-up`} />
25-
</svg>
26-
);
15+
if (process.env.NODE_ENV !== "production" && DevIcon) {
16+
return (
17+
<DevIcon
18+
{...(props as any)}
19+
{...(size != null ? { size } : {})}
20+
{...(width != null ? { width } : {})}
21+
{...(height != null ? { height } : {})}
22+
/>
23+
);
24+
}
25+
return renderUse("a-arrow-up", width, height, size, SPRITE_PATH, props)
2726
}
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
import { ALargeSmall as DevIcon, type LucideProps } from "lucide-react"
21
import { SPRITE_PATH } from "../config.js";
32
import { warnMissingIconSize } from "../utils.js";
3+
import { createRequire } from "module";
4+
import { renderUse,type IconProps,} from "../_shared.js";
45

5-
interface Props extends LucideProps { size?: number | string | undefined; width?: number | string | undefined; height?: number | string | undefined; }
6+
let DevIcon: ((p: IconProps) => React.JSX.Element) | undefined;
7+
if (process.env.NODE_ENV !== "production") {
8+
const require = createRequire(import.meta.url);
9+
const mod = require("lucide-react");
10+
DevIcon = mod.ALargeSmall as any;
11+
}
612

7-
export function ALargeSmall({ size, width, height, ...props }: Props) {
13+
export function ALargeSmall({ size, width, height, ...props }: IconProps) {
814
warnMissingIconSize("ALargeSmall", size, width, height);
9-
10-
return process.env.NODE_ENV !== "production" ? (
11-
<DevIcon
12-
{...props}
13-
{...(size != null ? { size } : {})}
14-
{...(width != null ? { width } : {})}
15-
{...(height != null ? { height } : {})}
16-
/>
17-
) : (
18-
<svg
19-
{...props}
20-
{...(size != null ? { width: size, height: size } : {})}
21-
{...(width != null ? { width } : {})}
22-
{...(height != null ? { height } : {})}
23-
>
24-
<use href={`${SPRITE_PATH}#a-large-small`} />
25-
</svg>
26-
);
15+
if (process.env.NODE_ENV !== "production" && DevIcon) {
16+
return (
17+
<DevIcon
18+
{...(props as any)}
19+
{...(size != null ? { size } : {})}
20+
{...(width != null ? { width } : {})}
21+
{...(height != null ? { height } : {})}
22+
/>
23+
);
24+
}
25+
return renderUse("a-large-small", width, height, size, SPRITE_PATH, props)
2726
}

0 commit comments

Comments
 (0)