Skip to content

Commit 3f69697

Browse files
committed
feat:config options
1 parent 0700ff2 commit 3f69697

File tree

8 files changed

+37
-15
lines changed

8 files changed

+37
-15
lines changed

next-app/app/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const Home: React.FC = () => {
3030
return <Icon key={index + `${icon}`} className="h-20 w-20" />
3131
})}
3232
<CustomIcon name="google-ads" size={80} />
33+
<CustomIcon name="ai" size={80} />
3334
<div className="flex-center border border-red-800">
3435
<AlarmClockCheck size={80} />
3536
</div>
Lines changed: 1 addition & 0 deletions
Loading

svg-sprite/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"types": "dist/index.d.ts",
99
"files": [
1010
"dist",
11-
"src/config.js",
12-
"src/config.d.ts",
1311
"scripts",
1412
"!/scripts/gen-dist.js",
1513
"!/scripts/gen-wrappers.js",
@@ -41,4 +39,4 @@
4139
"@types/react": "^19.1.9",
4240
"typescript": "^5.0.0"
4341
}
44-
}
42+
}

svg-sprite/scripts/build-sprite.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import path from "path";
44
import { createRequire } from "module";
55
import svgstore from "svgstore";
66
import { ICONS } from "./used-icons.js";
7-
import { SPRITE_PATH } from "../src/config.js";
8-
import { CUSTOM_SVG_DIR } from "../src/config.js";
7+
import { SPRITE_PATH, CUSTOM_SVG_DIR } from "../dist/config.js";
98

109
const require = createRequire(import.meta.url);
1110

svg-sprite/scripts/scan-icons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { fileURLToPath } from "url";
55
import * as babel from "@babel/core";
66
import traverseImport from "@babel/traverse";
77
import * as t from "@babel/types";
8-
import { IMPORT_NAME, ROOT_DIR } from "../src/config.js";
8+
import { IMPORT_NAME, ROOT_DIR } from "../dist/config.js";
99

1010
// ESM __dirname shim
1111
const __dirname = path.dirname(fileURLToPath(import.meta.url));

svg-sprite/src/config.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

svg-sprite/src/config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

svg-sprite/src/config.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import { createRequire } from "module";
4+
5+
// Default config
6+
let config = {
7+
IMPORT_NAME: "@react-zero-ui/svg-sprite",
8+
SPRITE_PATH: "/icons.svg",
9+
ROOT_DIR: "app",
10+
CUSTOM_SVG_DIR: "custom-icons",
11+
OUTPUT_DIR: "public",
12+
};
13+
14+
// Check for user config (synchronously)
15+
const userConfigPath = path.resolve(process.cwd(), "zero-ui.config.js");
16+
if (fs.existsSync(userConfigPath)) {
17+
try {
18+
const require = createRequire(import.meta.url);
19+
delete require.cache[userConfigPath]; // Clear cache for hot reloading
20+
const userConfig = require(userConfigPath);
21+
config = { ...config, ...userConfig };
22+
} catch (e) {
23+
// @ts-expect-error
24+
console.warn("⚠️ Failed to load zero-ui.config.js:", e.message);
25+
}
26+
}
27+
28+
export const IMPORT_NAME = config.IMPORT_NAME;
29+
export const SPRITE_PATH = config.SPRITE_PATH;
30+
export const ROOT_DIR = config.ROOT_DIR;
31+
export const CUSTOM_SVG_DIR = config.CUSTOM_SVG_DIR;
32+
export const OUTPUT_DIR = config.OUTPUT_DIR;

0 commit comments

Comments
 (0)