|
1 | 1 | // src/config.ts |
2 | | -import fs from "fs"; |
3 | | -import path from "path"; |
4 | | -import { pathToFileURL } from "url"; |
| 2 | +// Client-safe config - NO fs, NO Node.js modules |
| 3 | +// These are the default values. User overrides are applied at build time via CLI. |
5 | 4 |
|
6 | | -const DEFAULT_CONFIG = { |
7 | | - IMPORT_NAME: "@react-zero-ui/icon-sprite", |
8 | | - SPRITE_PATH: "/icons.svg", |
9 | | - ROOT_DIR: "src", |
10 | | - CUSTOM_SVG_DIR: "zero-ui-icons", |
11 | | - OUTPUT_DIR: "public", |
12 | | - IGNORE_ICONS: ["CustomIcon"], |
13 | | - EXCLUDE_DIRS: ["node_modules", ".git", "dist", "build", ".next", "out"], |
14 | | -}; |
15 | | - |
16 | | -let userConfig = {}; |
17 | | -const configFile = path.resolve(process.cwd(), "zero-ui.config.js"); |
18 | | - |
19 | | -if (fs.existsSync(configFile)) { |
20 | | - try { |
21 | | - const mod = await import(pathToFileURL(configFile).href); |
22 | | - userConfig = mod.default ?? mod; |
23 | | - } catch (e) { |
24 | | - // @ts-expect-error |
25 | | - console.warn("⚠️ Failed to load zero-ui.config.js:", e.message); |
26 | | - } |
| 5 | +/** Configuration options for zero-ui.config.js or zero-ui.config.ts */ |
| 6 | +export interface ZeroUIConfig { |
| 7 | + /** Package import name (default: "@react-zero-ui/icon-sprite") */ |
| 8 | + IMPORT_NAME?: string; |
| 9 | + /** Path to the sprite file relative to public dir (default: "/icons.svg") */ |
| 10 | + SPRITE_PATH?: string; |
| 11 | + /** Root directory to scan for icon imports (default: auto-detected from "src", "app", or "pages") */ |
| 12 | + ROOT_DIR?: string; |
| 13 | + /** Directory for custom SVG icons inside OUTPUT_DIR (default: "zero-ui-icons") */ |
| 14 | + CUSTOM_SVG_DIR?: string; |
| 15 | + /** Output directory for built assets (default: "public") */ |
| 16 | + OUTPUT_DIR?: string; |
| 17 | + /** Icon names to ignore during scanning (default: ["CustomIcon"]) */ |
| 18 | + IGNORE_ICONS?: string[]; |
| 19 | + /** Directories to exclude from scanning (default: ["node_modules", ".git", "dist", "build", ".next", "out"]) */ |
| 20 | + EXCLUDE_DIRS?: string[]; |
27 | 21 | } |
28 | 22 |
|
29 | | -const merged = { ...DEFAULT_CONFIG, ...userConfig }; |
30 | | - |
31 | | -export const IMPORT_NAME = merged.IMPORT_NAME; |
32 | | -export const SPRITE_PATH = merged.SPRITE_PATH; |
33 | | -export const ROOT_DIR = merged.ROOT_DIR; |
34 | | -export const CUSTOM_SVG_DIR = merged.CUSTOM_SVG_DIR; |
35 | | -export const OUTPUT_DIR = merged.OUTPUT_DIR; |
36 | | -export const IGNORE_ICONS = merged.IGNORE_ICONS; |
37 | | -export const EXCLUDE_DIRS = merged.EXCLUDE_DIRS; |
| 23 | +export const IMPORT_NAME = "@react-zero-ui/icon-sprite"; |
| 24 | +export const SPRITE_PATH = "/icons.svg"; |
| 25 | +export const ROOT_DIR = "src"; |
| 26 | +export const CUSTOM_SVG_DIR = "zero-ui-icons"; |
| 27 | +export const OUTPUT_DIR = "public"; |
| 28 | +export const IGNORE_ICONS = ["CustomIcon"]; |
| 29 | +export const EXCLUDE_DIRS = ["node_modules", ".git", "dist", "build", ".next", "out"]; |
0 commit comments