@4399ywkf/core 5.0.26 → 5.0.28

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,1153 @@
1
+ import { Configuration } from '@rspack/core';
2
+ import { a as AppConfig, P as ProviderConfig } from './types-BYqzyGAY.js';
3
+
4
+ /**
5
+ * 路由项定义
6
+ */
7
+ interface RouteItem {
8
+ /** 路由路径 */
9
+ path: string;
10
+ /** 组件文件路径(相对于 src) */
11
+ component: string;
12
+ /** 是否为 index 路由 */
13
+ index?: boolean;
14
+ /** 是否为布局组件 */
15
+ isLayout?: boolean;
16
+ /** 子路由 */
17
+ children?: RouteItem[];
18
+ /** 路由元信息 */
19
+ meta?: RouteMeta;
20
+ }
21
+ /**
22
+ * 路由元信息
23
+ */
24
+ interface RouteMeta {
25
+ /** 页面标题 */
26
+ title?: string;
27
+ /** 是否需要登录 */
28
+ auth?: boolean;
29
+ /** 自定义数据 */
30
+ [key: string]: unknown;
31
+ }
32
+
33
+ /**
34
+ * 插件上下文
35
+ */
36
+ interface PluginContext {
37
+ /** 工作目录 */
38
+ cwd: string;
39
+ /** 是否开发模式 */
40
+ isDev: boolean;
41
+ /** 是否生产模式 */
42
+ isProd: boolean;
43
+ /** 用户配置 */
44
+ config: Required<YwkfConfig>;
45
+ /** 日志工具 */
46
+ logger: PluginLogger;
47
+ }
48
+ /**
49
+ * 插件日志工具
50
+ */
51
+ interface PluginLogger {
52
+ info: (message: string) => void;
53
+ warn: (message: string) => void;
54
+ error: (message: string) => void;
55
+ debug: (message: string) => void;
56
+ }
57
+ /**
58
+ * 构建阶段钩子
59
+ */
60
+ interface BuildHooks {
61
+ /**
62
+ * 修改 Rspack 配置
63
+ */
64
+ modifyRspackConfig?: (config: Configuration, context: PluginContext) => Configuration | undefined | Promise<Configuration | undefined>;
65
+ /**
66
+ * 构建开始前
67
+ */
68
+ beforeBuild?: (context: PluginContext) => void | Promise<void>;
69
+ /**
70
+ * 构建完成后
71
+ */
72
+ afterBuild?: (context: PluginContext, stats: {
73
+ success: boolean;
74
+ errors?: string[];
75
+ }) => void | Promise<void>;
76
+ /**
77
+ * 开发服务器启动前
78
+ */
79
+ beforeDevServer?: (context: PluginContext) => void | Promise<void>;
80
+ /**
81
+ * 开发服务器启动后
82
+ */
83
+ afterDevServer?: (context: PluginContext, server: {
84
+ port: number;
85
+ host: string;
86
+ }) => void | Promise<void>;
87
+ }
88
+ /**
89
+ * 路由阶段钩子
90
+ */
91
+ interface RouterHooks {
92
+ /**
93
+ * 修改路由配置
94
+ */
95
+ modifyRoutes?: (routes: RouteItem[], context: PluginContext) => RouteItem[] | undefined | Promise<RouteItem[] | undefined>;
96
+ /**
97
+ * 路由生成后
98
+ */
99
+ afterRoutesGenerated?: (routes: RouteItem[], context: PluginContext) => void | Promise<void>;
100
+ }
101
+ /**
102
+ * 运行时阶段钩子
103
+ */
104
+ interface RuntimeHooks {
105
+ /**
106
+ * 修改运行时配置
107
+ */
108
+ modifyAppConfig?: (appConfig: AppConfig, context: PluginContext) => AppConfig | undefined;
109
+ /**
110
+ * 添加 Provider
111
+ */
112
+ addProvider?: (context: PluginContext) => ProviderConfig | ProviderConfig[];
113
+ /**
114
+ * 应用渲染前
115
+ */
116
+ beforeRender?: (context: PluginContext) => void;
117
+ /**
118
+ * 应用渲染后
119
+ */
120
+ afterRender?: (context: PluginContext) => void;
121
+ }
122
+ /**
123
+ * 生成的文件
124
+ */
125
+ interface GeneratedFile {
126
+ /** 文件路径(相对于 .ywkf 目录) */
127
+ path: string;
128
+ /** 文件内容 */
129
+ content: string;
130
+ }
131
+ /**
132
+ * 代码生成器上下文
133
+ */
134
+ interface GeneratorContext {
135
+ /** 工作目录 */
136
+ cwd: string;
137
+ /** 输出目录(.ywkf) */
138
+ outputDir: string;
139
+ /** 用户配置 */
140
+ config: Required<YwkfConfig>;
141
+ /** 是否开发模式 */
142
+ isDev: boolean;
143
+ }
144
+ /**
145
+ * 代码注入点
146
+ */
147
+ interface CodeInjection {
148
+ /** 导入语句 */
149
+ imports?: string[];
150
+ /** 顶层代码(在函数外部) */
151
+ topLevel?: string[];
152
+ /** 导出语句 */
153
+ exports?: string[];
154
+ }
155
+ /**
156
+ * 代码生成阶段钩子
157
+ */
158
+ interface GeneratorHooks {
159
+ /**
160
+ * 修改入口文件代码
161
+ */
162
+ modifyEntryCode?: (code: string, context: GeneratorContext) => string | undefined;
163
+ /**
164
+ * 修改启动文件代码
165
+ */
166
+ modifyBootstrapCode?: (code: string, context: GeneratorContext) => string | undefined;
167
+ /**
168
+ * 注入入口代码
169
+ * 返回需要注入到入口文件的代码片段
170
+ */
171
+ injectEntry?: (context: GeneratorContext) => CodeInjection | undefined;
172
+ /**
173
+ * 注入启动代码
174
+ * 返回需要注入到启动文件的代码片段
175
+ */
176
+ injectBootstrap?: (context: GeneratorContext) => CodeInjection | undefined;
177
+ /**
178
+ * 生成额外文件
179
+ */
180
+ generateFiles?: (context: GeneratorContext) => GeneratedFile[] | undefined;
181
+ /**
182
+ * 代码生成完成后
183
+ */
184
+ afterGenerate?: (context: GeneratorContext) => void | Promise<void>;
185
+ }
186
+ /**
187
+ * 插件钩子集合
188
+ */
189
+ interface PluginHooks extends BuildHooks, RouterHooks, RuntimeHooks, GeneratorHooks {
190
+ }
191
+ /**
192
+ * 插件定义
193
+ */
194
+ interface YwkfPlugin {
195
+ /** 插件名称 */
196
+ name: string;
197
+ /** 插件版本 */
198
+ version?: string;
199
+ /** 插件描述 */
200
+ description?: string;
201
+ /**
202
+ * 插件初始化
203
+ * @returns 插件钩子
204
+ */
205
+ setup: (context: PluginContext) => PluginHooks | Promise<PluginHooks>;
206
+ }
207
+ /**
208
+ * 插件配置(用户在 ywkf.config.ts 中使用)
209
+ */
210
+ type PluginConfig = string | YwkfPlugin | [string, Record<string, unknown>] | [YwkfPlugin, Record<string, unknown>];
211
+ /**
212
+ * 创建插件的辅助函数类型
213
+ */
214
+ type DefinePlugin = (options?: Record<string, unknown>) => YwkfPlugin;
215
+ /**
216
+ * 插件 API(传递给插件的 setup 函数)
217
+ */
218
+ interface PluginAPI {
219
+ /** 获取配置 */
220
+ getConfig: () => Required<YwkfConfig>;
221
+ /** 获取工作目录 */
222
+ getCwd: () => string;
223
+ /** 是否开发环境 */
224
+ isDev: () => boolean;
225
+ /** 添加 Rspack 插件 */
226
+ addRspackPlugin: (plugin: unknown) => void;
227
+ /** 修改 Rspack 配置 */
228
+ modifyRspackConfig: (modifier: (config: Configuration) => Configuration | undefined) => void;
229
+ }
230
+
231
+ interface AnalyticsPluginOptions {
232
+ /** 是否启用构建分析 */
233
+ buildAnalysis?: boolean;
234
+ /** 是否输出构建时间 */
235
+ timing?: boolean;
236
+ /** 是否分析 bundle 大小 */
237
+ bundleSize?: boolean;
238
+ /** 大文件警告阈值(KB) */
239
+ sizeWarningThreshold?: number;
240
+ }
241
+ /**
242
+ * 构建分析插件
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * import { analyticsPlugin } from "@4399ywkf/core/plugin";
247
+ *
248
+ * export default defineConfig({
249
+ * plugins: [
250
+ * analyticsPlugin({
251
+ * timing: true,
252
+ * bundleSize: true,
253
+ * sizeWarningThreshold: 500, // 500KB
254
+ * }),
255
+ * ],
256
+ * });
257
+ * ```
258
+ */
259
+ declare const analyticsPlugin: (options?: AnalyticsPluginOptions | undefined) => YwkfPlugin;
260
+
261
+ interface BiomePluginOptions {
262
+ /**
263
+ * 是否在项目根目录生成 biome.json(仅在文件不存在时)
264
+ * @default true
265
+ */
266
+ scaffold?: boolean;
267
+ /**
268
+ * 额外忽略的文件 glob
269
+ */
270
+ ignore?: string[];
271
+ /**
272
+ * 自定义 linter 规则覆盖(浅合并到继承的规则上)
273
+ */
274
+ rules?: Record<string, Record<string, string>>;
275
+ /**
276
+ * 自定义 formatter 覆盖
277
+ */
278
+ formatter?: Record<string, unknown>;
279
+ /**
280
+ * 自定义 javascript formatter 覆盖
281
+ */
282
+ javascript?: Record<string, unknown>;
283
+ }
284
+ /**
285
+ * Biome 代码规范插件
286
+ *
287
+ * 在 setup 阶段自动生成 biome.json,通过 extends 继承
288
+ * @4399ywkf/core 内置的共享配置,为项目提供统一的
289
+ * Lint / Format / Import Sorting 规范。
290
+ *
291
+ * 用户项目的 biome.json 只需 extends 框架配置,
292
+ * 再按需覆盖少量规则即可。
293
+ *
294
+ * @example
295
+ * ```ts
296
+ * import { defineConfig, biomePlugin } from "@4399ywkf/core";
297
+ *
298
+ * export default defineConfig({
299
+ * plugins: [
300
+ * biomePlugin(),
301
+ * ],
302
+ * });
303
+ * ```
304
+ */
305
+ declare const biomePlugin: (options?: BiomePluginOptions | undefined) => YwkfPlugin;
306
+ /**
307
+ * 生成默认 biome.json 配置内容(纯数据,供 CLI 脚手架使用)
308
+ *
309
+ * 生成的配置通过 extends 继承 @4399ywkf/core/biome 共享配置,
310
+ * 用户只需在此基础上按需覆盖。
311
+ */
312
+ declare function getDefaultBiomeConfig(): Record<string, unknown>;
313
+
314
+ /**
315
+ * 浏览器版本要求
316
+ */
317
+ interface BrowserMinVersions {
318
+ chrome?: number;
319
+ edge?: number;
320
+ firefox?: number;
321
+ safari?: number;
322
+ }
323
+ interface BrowserCheckPluginOptions {
324
+ /**
325
+ * 需要检测的浏览器特性(API 级别的特性检测)
326
+ * @default ["Object.hasOwn"]
327
+ * @example ["Object.hasOwn", "Array.prototype.at", "structuredClone"]
328
+ */
329
+ features?: string[];
330
+ /**
331
+ * 最低浏览器版本要求(基于 UA 解析)
332
+ *
333
+ * 优先级:`minVersions` > `fromBrowserslist` 解析结果 > 内置默认值
334
+ *
335
+ * @default { chrome: 93, edge: 93, firefox: 92, safari: 15.4 }
336
+ */
337
+ minVersions?: BrowserMinVersions;
338
+ /**
339
+ * 从 `.browserslistrc` 文件或 `package.json` 的 `browserslist` 字段中
340
+ * 自动读取最低浏览器版本要求。
341
+ *
342
+ * - `true` — 自动在项目根目录查找 `.browserslistrc` 或 `package.json#browserslist`
343
+ * - `string` — 指定 `.browserslistrc` 文件的路径(相对于项目根目录)
344
+ * - `false` — 不读取,使用 `minVersions` 或内置默认值
345
+ *
346
+ * 如果同时配置了 `minVersions`,`minVersions` 中的值会**覆盖** `.browserslistrc` 中的对应值。
347
+ *
348
+ * @default false
349
+ *
350
+ * @example
351
+ * ```ts
352
+ * // 自动检测
353
+ * browserCheckPlugin({ fromBrowserslist: true })
354
+ *
355
+ * // 指定路径
356
+ * browserCheckPlugin({ fromBrowserslist: "../.browserslistrc" })
357
+ *
358
+ * // 自动读取 + 覆盖 safari 版本
359
+ * browserCheckPlugin({ fromBrowserslist: true, minVersions: { safari: 16 } })
360
+ * ```
361
+ */
362
+ fromBrowserslist?: boolean | string;
363
+ /**
364
+ * 警告页面标题
365
+ * @default "浏览器版本过低"
366
+ */
367
+ title?: string;
368
+ /**
369
+ * 警告页面描述信息
370
+ * @default "您当前的浏览器版本不支持本应用所需的功能。请升级到以下推荐浏览器的最新版本:"
371
+ */
372
+ message?: string;
373
+ /**
374
+ * 是否显示推荐浏览器下载链接
375
+ * @default true
376
+ */
377
+ showDownloadLinks?: boolean;
378
+ /**
379
+ * 自定义渲染 HTML 的函数。如果提供,将替代默认的警告页面。
380
+ */
381
+ renderHtml?: (opts: {
382
+ title: string;
383
+ message: string;
384
+ showDownloadLinks: boolean;
385
+ minVersions: BrowserMinVersions;
386
+ }) => string;
387
+ /**
388
+ * 伴随自定义 HTML 执行的 JS 脚本代码(字符串形式)。
389
+ * 注意:这段代码会在不支持的浏览器中执行,请使用 ES5 语法。
390
+ */
391
+ renderScript?: string;
392
+ }
393
+ /**
394
+ * 浏览器最低版本检查插件
395
+ *
396
+ * 在应用启动前检测浏览器兼容性,若不满足要求则展示升级提示页面,阻止应用加载。
397
+ * 支持两种检测策略:
398
+ * 1. **特性检测**(推荐):检查浏览器是否支持指定的 API,如 `Object.hasOwn`
399
+ * 2. **UA 版本检测**:解析 User-Agent 判断浏览器版本是否达到最低要求
400
+ *
401
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn
402
+ *
403
+ * @example
404
+ * ```ts
405
+ * import { defineConfig, browserCheckPlugin } from "@4399ywkf/core";
406
+ *
407
+ * export default defineConfig({
408
+ * plugins: [
409
+ * browserCheckPlugin(),
410
+ * ],
411
+ * });
412
+ * ```
413
+ *
414
+ * @example
415
+ * ```ts
416
+ * // 自定义最低版本和检测特性
417
+ * browserCheckPlugin({
418
+ * features: ["Object.hasOwn", "Array.prototype.at"],
419
+ * minVersions: { chrome: 100, edge: 100, firefox: 100, safari: 16 },
420
+ * title: "请升级浏览器",
421
+ * message: "当前浏览器版本过低,无法正常使用本系统。",
422
+ * })
423
+ * ```
424
+ *
425
+ * @example
426
+ * ```ts
427
+ * // 从 .browserslistrc 自动读取最低版本要求
428
+ * browserCheckPlugin({
429
+ * fromBrowserslist: true,
430
+ * })
431
+ * ```
432
+ *
433
+ * @example
434
+ * ```ts
435
+ * // 从 .browserslistrc 读取,并覆盖 safari 版本
436
+ * browserCheckPlugin({
437
+ * fromBrowserslist: true,
438
+ * minVersions: { safari: 16 },
439
+ * })
440
+ * ```
441
+ */
442
+ declare const browserCheckPlugin: (options?: BrowserCheckPluginOptions | undefined) => YwkfPlugin;
443
+
444
+ interface GarfishPluginOptions {
445
+ /** 应用名称(微前端标识) */
446
+ appName?: string;
447
+ /** 是否作为主应用 */
448
+ master?: boolean;
449
+ /** 子应用列表(主应用模式) */
450
+ apps?: {
451
+ name: string;
452
+ entry: string;
453
+ activeRule: string;
454
+ basename?: string;
455
+ }[];
456
+ /** 沙箱配置 */
457
+ sandbox?: {
458
+ /** 是否开启 JS 沙箱 */
459
+ open?: boolean;
460
+ /** 是否开启快照沙箱 */
461
+ snapshot?: boolean;
462
+ /** 样式隔离 */
463
+ strictStyleIsolation?: boolean;
464
+ };
465
+ }
466
+ /**
467
+ * Garfish 微前端插件
468
+ *
469
+ * 通过插件方式启用微前端功能,支持子应用和主应用两种模式。
470
+ *
471
+ * @example
472
+ * ```ts
473
+ * // ywkf.config.ts - 子应用模式
474
+ * import { defineConfig, garfishPlugin } from "@4399ywkf/core";
475
+ *
476
+ * export default defineConfig({
477
+ * plugins: [
478
+ * garfishPlugin({
479
+ * appName: "sub-app",
480
+ * }),
481
+ * ],
482
+ * });
483
+ * ```
484
+ *
485
+ * @example
486
+ * ```ts
487
+ * // ywkf.config.ts - 主应用模式
488
+ * import { defineConfig, garfishPlugin } from "@4399ywkf/core";
489
+ *
490
+ * export default defineConfig({
491
+ * plugins: [
492
+ * garfishPlugin({
493
+ * master: true,
494
+ * apps: [
495
+ * { name: "sub-app", entry: "http://localhost:3001", activeRule: "/sub" },
496
+ * ],
497
+ * }),
498
+ * ],
499
+ * });
500
+ * ```
501
+ */
502
+ declare const garfishPlugin: (options?: GarfishPluginOptions | undefined) => YwkfPlugin;
503
+
504
+ interface I18nPluginOptions {
505
+ /**
506
+ * 默认语言
507
+ * @default "zh-CN"
508
+ */
509
+ defaultLocale?: string;
510
+ /**
511
+ * 支持的语言列表
512
+ * @default ["zh-CN", "en-US"]
513
+ */
514
+ locales?: string[];
515
+ /**
516
+ * 翻译 JSON 文件目录(相对于项目根目录)
517
+ * 非默认语言的 JSON 翻译文件存放位置
518
+ * @default "locales"
519
+ */
520
+ localesDir?: string;
521
+ /**
522
+ * 默认语言 TS 源文件目录(相对于项目根目录)
523
+ * 开发者在此编写 TypeScript 翻译源文件,作为 i18n 的 single source of truth
524
+ * @default "src/locales/default"
525
+ */
526
+ sourceDir?: string;
527
+ /**
528
+ * 默认命名空间
529
+ * @default ["common"]
530
+ */
531
+ defaultNS?: string[];
532
+ /**
533
+ * 是否自动生成初始脚手架文件
534
+ * @default true
535
+ */
536
+ autoScaffold?: boolean;
537
+ }
538
+ /**
539
+ * 国际化插件(TS-first 工作流)
540
+ *
541
+ * 开发流程:
542
+ * 1. 开发者在 src/locales/default/ 中编写 TypeScript 翻译源文件(有类型推导 + IDE 补全)
543
+ * 2. 运行 `pnpm i18n:gen` 将 TS 源文件转换为 locales/{defaultLocale}/*.json
544
+ * 3. 运行 `pnpm i18n` 使用 @lobehub/i18n-cli 将默认语言 JSON 翻译为其他语言
545
+ * 4. 运行时:开发模式下默认语言直接 import TS,其他场景懒加载 JSON
546
+ *
547
+ * @example
548
+ * ```ts
549
+ * import { defineConfig, i18nPlugin } from "@4399ywkf/core";
550
+ *
551
+ * export default defineConfig({
552
+ * plugins: [
553
+ * i18nPlugin({
554
+ * defaultLocale: "zh-CN",
555
+ * locales: ["zh-CN", "en-US", "ja-JP"],
556
+ * }),
557
+ * ],
558
+ * });
559
+ * ```
560
+ */
561
+ declare const i18nPlugin: (options?: I18nPluginOptions | undefined) => YwkfPlugin;
562
+
563
+ interface MockPluginOptions {
564
+ /** Mock 文件目录 */
565
+ mockDir?: string;
566
+ /** 是否在生产环境启用 */
567
+ enableInProd?: boolean;
568
+ /** 延迟时间(模拟网络延迟) */
569
+ delay?: number;
570
+ /** 前缀路径 */
571
+ prefix?: string;
572
+ }
573
+ /**
574
+ * Mock 数据插件
575
+ *
576
+ * @example
577
+ * ```ts
578
+ * // ywkf.config.ts
579
+ * import { mockPlugin } from "@4399ywkf/core/plugin";
580
+ *
581
+ * export default defineConfig({
582
+ * plugins: [
583
+ * mockPlugin({
584
+ * mockDir: "mock",
585
+ * prefix: "/api",
586
+ * }),
587
+ * ],
588
+ * });
589
+ * ```
590
+ *
591
+ * Mock 文件示例 (mock/user.ts):
592
+ * ```ts
593
+ * export default {
594
+ * "GET /api/users": [
595
+ * { id: 1, name: "张三" },
596
+ * ],
597
+ * "POST /api/users": (req, res) => {
598
+ * res.json({ success: true });
599
+ * },
600
+ * };
601
+ * ```
602
+ */
603
+ declare const mockPlugin: (options?: MockPluginOptions | undefined) => YwkfPlugin;
604
+
605
+ interface ReactQueryPluginOptions {
606
+ /**
607
+ * 默认 staleTime(毫秒)
608
+ * @default 5 * 60 * 1000 (5 分钟)
609
+ */
610
+ staleTime?: number;
611
+ /**
612
+ * 默认 gcTime(毫秒)
613
+ * @default 10 * 60 * 1000 (10 分钟)
614
+ */
615
+ gcTime?: number;
616
+ /**
617
+ * 默认重试次数
618
+ * @default 1
619
+ */
620
+ retry?: number | boolean;
621
+ /**
622
+ * 是否开启 React Query DevTools(仅开发模式生效)
623
+ * @default true
624
+ */
625
+ devtools?: boolean;
626
+ /**
627
+ * axios baseURL
628
+ * @default ""
629
+ */
630
+ baseURL?: string;
631
+ /**
632
+ * 请求超时时间(毫秒)
633
+ * @default 15000
634
+ */
635
+ timeout?: number;
636
+ }
637
+ /**
638
+ * React Query + Axios 请求层插件
639
+ *
640
+ * - 自动注入 QueryClientProvider
641
+ * - 生成 .ywkf/query-client.ts(QueryClient 实例 + 默认配置)
642
+ * - 生成 .ywkf/request.ts(axios 封装 + 拦截器骨架)
643
+ * - 开发模式可选开启 React Query DevTools
644
+ *
645
+ * @example
646
+ * ```ts
647
+ * import { defineConfig, reactQueryPlugin } from "@4399ywkf/core";
648
+ *
649
+ * export default defineConfig({
650
+ * plugins: [
651
+ * reactQueryPlugin({ staleTime: 5 * 60 * 1000 }),
652
+ * ],
653
+ * });
654
+ * ```
655
+ */
656
+ declare const reactQueryPlugin: (options?: ReactQueryPluginOptions | undefined) => YwkfPlugin;
657
+
658
+ interface TailwindPluginOptions {
659
+ /**
660
+ * 自定义暗色模式选择器
661
+ * @default '&:where([data-theme="dark"], [data-theme="dark"] *)'
662
+ */
663
+ darkModeSelector?: string;
664
+ /**
665
+ * 是否生成 postcss.config.js(如果不存在)
666
+ * @default true
667
+ */
668
+ autoConfig?: boolean;
669
+ /**
670
+ * 额外的 CSS 内容(追加到 index.css 之后)
671
+ */
672
+ extraCSS?: string;
673
+ }
674
+ /**
675
+ * Tailwind CSS 插件
676
+ *
677
+ * 自动配置 Tailwind CSS:
678
+ * - 注入 `@import "tailwindcss"` 到 index.css
679
+ * - 确保 postcss.config.js 存在
680
+ * - 修改 Rspack 配置添加 postcss-loader
681
+ *
682
+ * @example
683
+ * ```ts
684
+ * import { defineConfig, tailwindPlugin } from "@4399ywkf/core";
685
+ *
686
+ * export default defineConfig({
687
+ * plugins: [
688
+ * tailwindPlugin(),
689
+ * ],
690
+ * });
691
+ * ```
692
+ */
693
+ declare const tailwindPlugin: (options?: TailwindPluginOptions | undefined) => YwkfPlugin;
694
+
695
+ interface ThemePluginOptions {
696
+ /**
697
+ * 是否启用暗色模式切换能力
698
+ * @default true
699
+ */
700
+ darkMode?: boolean;
701
+ /**
702
+ * 默认主题模式(运行时可通过 useThemeStore 动态切换)
703
+ * @default "light"
704
+ */
705
+ defaultAppearance?: "light" | "dark" | "auto";
706
+ /**
707
+ * 主色调(Lobe-UI 命名预设,运行时可通过 useThemeStore 动态切换)
708
+ *
709
+ * 不设置时使用 Lobe-UI 默认 primary 色阶(黑色系),
710
+ * 可选值:"blue" | "cyan" | "geekblue" | "gold" | "green" | "lime"
711
+ * | "magenta" | "orange" | "purple" | "red" | "volcano" | "yellow"
712
+ *
713
+ * @default undefined
714
+ */
715
+ primaryColor?: string;
716
+ /**
717
+ * 中性色(Lobe-UI 命名预设)
718
+ *
719
+ * 可选值:"mauve" | "olive" | "sage" | "sand" | "slate"
720
+ *
721
+ * @default undefined
722
+ */
723
+ neutralColor?: string;
724
+ /**
725
+ * antd 组件前缀
726
+ *
727
+ * 支持三种配置方式(优先级从高到低):
728
+ * 1. 运行时环境变量 process.env.YWKF_PREFIX_CLS
729
+ * 2. 插件选项中直接指定
730
+ * 3. 默认值 "ant"
731
+ *
732
+ * @default "ant"
733
+ */
734
+ prefixCls?: string;
735
+ /**
736
+ * 是否启用 CSS 变量
737
+ * @default true
738
+ */
739
+ cssVar?: boolean;
740
+ /**
741
+ * 是否注入全局样式重置
742
+ * @default true
743
+ */
744
+ globalReset?: boolean;
745
+ /**
746
+ * 是否启用外部主题注入(微前端场景)
747
+ *
748
+ * 启用后:
749
+ * - 应用启动时读取 window.__YWKF_THEME__ 作为初始覆盖
750
+ * - 监听 ywkf:theme-change 自定义事件,实现运行时主题同步
751
+ *
752
+ * @default false
753
+ */
754
+ externalTheme?: boolean;
755
+ /**
756
+ * antd 国际化 locale 配置
757
+ *
758
+ * - `"auto"`(默认):运行时自动检测并动态加载对应的 antd 语言包,兜底 zhCN。
759
+ * 检测优先级:`window.__YWKF_LOCALE__`(微前端注入)> `navigator.language` > `"zh-CN"`
760
+ *
761
+ * auto 模式下 locale 被纳入 ThemeStore,支持:
762
+ * - 用户代码通过 `useThemeStore.getState().setLocale("en-US")` 运行时切换
763
+ * - 微前端主应用通过 `ywkf:locale-change` 自定义事件同步 locale
764
+ * - 便捷 hook `useLocale()` 获取当前 locale(BCP 47 tag)
765
+ *
766
+ * - 指定具体名称(如 `"zhCN"` / `"enUS"`):静态导入该语言包,无运行时开销,
767
+ * locale 仍会写入 ThemeStore 但不会自动检测或监听外部事件
768
+ *
769
+ * @default "auto"
770
+ */
771
+ locale?: "zhCN" | "enUS" | "zhTW" | "jaJP" | "koKR" | "auto";
772
+ /**
773
+ * 将 Tooltip / Dropdown / Modal 等弹层的挂载节点限定在 ThemeWrapper 容器内
774
+ *
775
+ * 解决问题:antd 弹层默认挂载到 document.body,在以下场景会导致样式失效:
776
+ * - 微前端子应用使用 StyleProvider 将样式注入到子应用容器,弹层挂载 body 后脱离样式范围
777
+ * - CSS 变量作用域被限定在特定容器,body 上的弹层无法继承
778
+ *
779
+ * 启用后会在 ThemeWrapper 内创建一个 `data-ywkf-root` 容器作为弹层挂载点,
780
+ * 该容器始终是 StyleProvider 的子孙节点,样式链路不会断裂。
781
+ *
782
+ * @default true
783
+ */
784
+ scopePopupContainer?: boolean;
785
+ }
786
+ /**
787
+ * 响应式主题系统插件
788
+ *
789
+ * 基于 antd-style + @4399ywkf/theme-system + Zustand 提供运行时可变的主题管理:
790
+ * - 使用 Lobe-UI 色彩体系(13 阶色阶 + 自定义算法)
791
+ * - 支持 PrimaryColors / NeutralColors 命名预设
792
+ * - 亮/暗色/跟随系统自动切换
793
+ * - 支持微前端场景主应用注入主题
794
+ *
795
+ * @example
796
+ * ```ts
797
+ * import { defineConfig, themePlugin } from "@4399ywkf/core";
798
+ *
799
+ * export default defineConfig({
800
+ * plugins: [
801
+ * themePlugin({
802
+ * defaultAppearance: "light",
803
+ * primaryColor: "geekblue",
804
+ * neutralColor: "slate",
805
+ * prefixCls: "my-app",
806
+ * }),
807
+ * ],
808
+ * });
809
+ * ```
810
+ */
811
+ declare const themePlugin: (options?: ThemePluginOptions | undefined) => YwkfPlugin;
812
+
813
+ interface ZustandPluginOptions {
814
+ /**
815
+ * 是否自动生成 store 脚手架(仅在 store/ 目录不存在时)
816
+ * @default true
817
+ */
818
+ scaffold?: boolean;
819
+ /**
820
+ * store 目录路径(相对于项目根目录)
821
+ * @default "store"
822
+ */
823
+ storeDir?: string;
824
+ }
825
+ /**
826
+ * Zustand 状态管理插件
827
+ *
828
+ * 采用扁平域/Slice 架构:
829
+ * - store/{domain}/slices/ 按业务域拆分
830
+ * - 每个 slice 拆为 initialState.ts + actions.ts
831
+ * - 域级 store.ts 聚合所有 slice
832
+ * - 使用 StateCreator<Store, [['zustand/devtools', never]], [], Action> 标准范式
833
+ * - 内置 devtools + subscribeWithSelector 中间件
834
+ *
835
+ * @example
836
+ * ```ts
837
+ * import { defineConfig, zustandPlugin } from "@4399ywkf/core";
838
+ *
839
+ * export default defineConfig({
840
+ * plugins: [
841
+ * zustandPlugin(),
842
+ * ],
843
+ * });
844
+ * ```
845
+ */
846
+ declare const zustandPlugin: (options?: ZustandPluginOptions | undefined) => YwkfPlugin;
847
+
848
+ /**
849
+ * 开发服务器配置
850
+ */
851
+ interface DevServerConfig {
852
+ /** 开发服务器端口 */
853
+ port?: number;
854
+ /** 开发服务器主机 */
855
+ host?: string;
856
+ /** 代理配置 */
857
+ proxy?: Record<string, string | object>;
858
+ /** 是否开启 HTTPS */
859
+ https?: boolean;
860
+ }
861
+ /**
862
+ * 输出配置
863
+ */
864
+ interface OutputConfig {
865
+ /** 输出目录 */
866
+ path?: string;
867
+ /** 公共路径 */
868
+ publicPath?: string;
869
+ /** 是否清理输出目录 */
870
+ clean?: boolean;
871
+ }
872
+ /**
873
+ * HTML 配置
874
+ */
875
+ interface HtmlConfig {
876
+ /** 页面标题 */
877
+ title?: string;
878
+ /** HTML 模板路径 */
879
+ template?: string;
880
+ /** favicon 路径 */
881
+ favicon?: string;
882
+ /** 挂载根元素 ID */
883
+ mountRoot?: string;
884
+ }
885
+ /**
886
+ * 样式配置
887
+ */
888
+ interface StyleConfig {
889
+ /** 是否启用 CSS Modules */
890
+ cssModules?: boolean;
891
+ /** Less 配置 */
892
+ less?: {
893
+ /** 是否启用 */
894
+ enabled?: boolean;
895
+ /** Less 选项 */
896
+ lessOptions?: Record<string, unknown>;
897
+ };
898
+ /** Sass 配置 */
899
+ sass?: {
900
+ /** 是否启用 */
901
+ enabled?: boolean;
902
+ /** Sass 选项 */
903
+ sassOptions?: Record<string, unknown>;
904
+ };
905
+ /** 是否启用 TailwindCSS */
906
+ tailwindcss?: boolean;
907
+ }
908
+ /**
909
+ * 路由配置
910
+ */
911
+ interface RouterConfig {
912
+ /** 路由基础路径 */
913
+ basename?: string;
914
+ /** 是否启用约定式路由 */
915
+ conventional?: boolean;
916
+ /** 约定式路由扫描目录 */
917
+ pagesDir?: string;
918
+ /** 排除的文件/目录模式 */
919
+ exclude?: (string | RegExp)[];
920
+ /**
921
+ * 懒加载的加载状态配置
922
+ * - `false`:禁用全局默认加载状态(各路由仍可通过 loading.tsx 单独配置)
923
+ * - `{ component: string }`:自定义全局默认加载组件的导入路径
924
+ * - 不配置:使用内置默认加载组件
925
+ *
926
+ * @example
927
+ * // 禁用加载状态
928
+ * loading: false
929
+ *
930
+ * @example
931
+ * // 自定义加载组件
932
+ * loading: { component: "@/components/Loading" }
933
+ */
934
+ loading?: false | {
935
+ component: string;
936
+ };
937
+ }
938
+ /**
939
+ * 微前端配置
940
+ */
941
+ interface MicroFrontendConfig {
942
+ /** 是否启用微前端模式 */
943
+ enabled?: boolean;
944
+ /** 应用名称(用于 UMD 导出) */
945
+ name?: string;
946
+ /** 微前端框架类型 */
947
+ framework?: "qiankun" | "garfish";
948
+ }
949
+ /**
950
+ * 性能配置
951
+ */
952
+ interface PerformanceConfig {
953
+ /** 是否启用 Rsdoctor 分析 */
954
+ rsdoctor?: boolean;
955
+ /** 是否开启代码分割 */
956
+ splitChunks?: boolean;
957
+ /** 是否移除 console */
958
+ dropConsole?: boolean;
959
+ }
960
+ /**
961
+ * 工具链配置
962
+ */
963
+ interface ToolsConfig {
964
+ /**
965
+ * 自定义 Rspack 配置
966
+ * @param config 当前配置
967
+ * @param context 上下文信息
968
+ * @returns 修改后的配置
969
+ */
970
+ rspack?: (config: Configuration, context: {
971
+ isDev: boolean;
972
+ isProd: boolean;
973
+ }) => Configuration | undefined;
974
+ }
975
+ /**
976
+ * 环境变量配置
977
+ */
978
+ interface EnvConfig {
979
+ /** 公共环境变量文件路径 */
980
+ publicEnvFile?: string;
981
+ /** 环境特定的变量文件目录 */
982
+ envDir?: string;
983
+ }
984
+ /**
985
+ * 内置插件快捷配置
986
+ *
987
+ * 这些插件默认启用,无需手动 import 和声明。
988
+ * 设为 `false` 可禁用,传入配置对象可自定义参数。
989
+ *
990
+ * @example
991
+ * ```ts
992
+ * defineConfig({
993
+ * // 禁用 zustand
994
+ * zustand: false,
995
+ * // 自定义 reactQuery 参数
996
+ * reactQuery: { timeout: 30000 },
997
+ * })
998
+ * ```
999
+ */
1000
+ interface BuiltinPluginConfig {
1001
+ /**
1002
+ * React Query + Axios 请求层(默认启用)
1003
+ *
1004
+ * 设为 `false` 禁用;传入配置对象自定义参数。
1005
+ * @default {} (启用,使用默认配置)
1006
+ */
1007
+ reactQuery?: ReactQueryPluginOptions | false;
1008
+ /**
1009
+ * Zustand 状态管理(默认启用)
1010
+ *
1011
+ * 设为 `false` 禁用;传入配置对象自定义参数。
1012
+ * @default {} (启用,使用默认配置)
1013
+ */
1014
+ zustand?: ZustandPluginOptions | false;
1015
+ /**
1016
+ * Tailwind CSS(默认启用)
1017
+ *
1018
+ * 设为 `false` 禁用;传入配置对象自定义参数。
1019
+ * @default {} (启用,使用默认配置)
1020
+ */
1021
+ tailwind?: TailwindPluginOptions | false;
1022
+ }
1023
+ /**
1024
+ * 可选插件快捷配置
1025
+ *
1026
+ * 这些插件默认不启用,配置后自动启用。
1027
+ * 设为 `true` 使用默认配置启用,传入配置对象可自定义参数。
1028
+ *
1029
+ * @example
1030
+ * ```ts
1031
+ * defineConfig({
1032
+ * theme: { darkMode: true, locale: "auto" },
1033
+ * browserCheck: { fromBrowserslist: true },
1034
+ * })
1035
+ * ```
1036
+ */
1037
+ interface OptionalPluginConfig {
1038
+ /**
1039
+ * antd-style 主题系统
1040
+ *
1041
+ * 设为 `true` 使用默认配置启用,或传入 ThemePluginOptions 自定义。
1042
+ */
1043
+ theme?: ThemePluginOptions | true;
1044
+ /**
1045
+ * 国际化 (i18next)
1046
+ *
1047
+ * 设为 `true` 使用默认配置启用,或传入 I18nPluginOptions 自定义。
1048
+ */
1049
+ i18n?: I18nPluginOptions | true;
1050
+ /**
1051
+ * 微前端 (Garfish)
1052
+ *
1053
+ * 传入 GarfishPluginOptions 配置。
1054
+ */
1055
+ garfish?: GarfishPluginOptions;
1056
+ /**
1057
+ * 浏览器兼容性检查
1058
+ *
1059
+ * 设为 `true` 使用默认配置启用,或传入 BrowserCheckPluginOptions 自定义。
1060
+ */
1061
+ browserCheck?: BrowserCheckPluginOptions | true;
1062
+ /**
1063
+ * Biome 代码规范
1064
+ *
1065
+ * 设为 `true` 使用默认配置启用,或传入 BiomePluginOptions 自定义。
1066
+ */
1067
+ biome?: BiomePluginOptions | true;
1068
+ /**
1069
+ * Mock 数据服务
1070
+ *
1071
+ * 设为 `true` 使用默认配置启用,或传入 MockPluginOptions 自定义。
1072
+ */
1073
+ mock?: MockPluginOptions | true;
1074
+ /**
1075
+ * 构建分析
1076
+ *
1077
+ * 设为 `true` 使用默认配置启用,或传入 AnalyticsPluginOptions 自定义。
1078
+ */
1079
+ analytics?: AnalyticsPluginOptions | true;
1080
+ }
1081
+ /**
1082
+ * 框架内部配置(不含插件快捷键)
1083
+ *
1084
+ * 内部模块使用此类型,通过 `Required<YwkfConfig>` 确保所有字段有值。
1085
+ */
1086
+ interface YwkfConfig {
1087
+ /** 应用名称 */
1088
+ appName?: string;
1089
+ /** 应用中文名 */
1090
+ appCName?: string;
1091
+ /** 开发服务器配置 */
1092
+ dev?: DevServerConfig;
1093
+ /** 输出配置 */
1094
+ output?: OutputConfig;
1095
+ /** HTML 配置 */
1096
+ html?: HtmlConfig;
1097
+ /** 样式配置 */
1098
+ style?: StyleConfig;
1099
+ /** 路由配置 */
1100
+ router?: RouterConfig;
1101
+ /** 微前端配置 */
1102
+ microFrontend?: MicroFrontendConfig;
1103
+ /** 性能配置 */
1104
+ performance?: PerformanceConfig;
1105
+ /** 工具链配置 */
1106
+ tools?: ToolsConfig;
1107
+ /** 环境变量配置 */
1108
+ env?: EnvConfig;
1109
+ /** 路径别名 */
1110
+ alias?: Record<string, string>;
1111
+ /** 插件列表 */
1112
+ plugins?: PluginConfig[];
1113
+ }
1114
+ /**
1115
+ * 用户输入配置(支持插件快捷键)
1116
+ *
1117
+ * 支持两种插件声明方式(可混用):
1118
+ *
1119
+ * **方式一:快捷配置(推荐)**
1120
+ * ```ts
1121
+ * defineConfig({
1122
+ * appName: "my-app",
1123
+ * theme: { darkMode: true },
1124
+ * browserCheck: { fromBrowserslist: true },
1125
+ * })
1126
+ * ```
1127
+ *
1128
+ * **方式二:手动插件(完全控制)**
1129
+ * ```ts
1130
+ * import { themePlugin, browserCheckPlugin } from "@4399ywkf/core";
1131
+ * defineConfig({
1132
+ * plugins: [themePlugin({ darkMode: true }), browserCheckPlugin()],
1133
+ * })
1134
+ * ```
1135
+ *
1136
+ * 两种方式可以混合使用。快捷配置中的插件与 `plugins` 数组合并时,
1137
+ * 同名插件以 `plugins` 数组中的为准(显式声明优先)。
1138
+ */
1139
+ interface YwkfUserConfig extends YwkfConfig, BuiltinPluginConfig, OptionalPluginConfig {
1140
+ }
1141
+ /**
1142
+ * 定义配置的辅助函数(提供类型提示)
1143
+ *
1144
+ * 接受 `YwkfUserConfig`(含插件快捷键),返回 `YwkfConfig`(内部类型)。
1145
+ * 类型转换在运行时由 `normalizeConfig` 完成。
1146
+ */
1147
+ declare function defineConfig(config: YwkfUserConfig): YwkfConfig;
1148
+ /**
1149
+ * 默认配置
1150
+ */
1151
+ declare const defaultConfig: Required<YwkfConfig>;
1152
+
1153
+ export { type AnalyticsPluginOptions as A, type BuiltinPluginConfig as B, type CodeInjection as C, type DevServerConfig as D, type EnvConfig as E, type GeneratedFile as F, type GeneratorContext as G, type HtmlConfig as H, type I18nPluginOptions as I, type GeneratorHooks as J, type PluginContext as K, type RouterHooks as L, type MicroFrontendConfig as M, type RuntimeHooks as N, type OptionalPluginConfig as O, type PerformanceConfig as P, type YwkfPlugin as Q, type RouterConfig as R, type StyleConfig as S, type ToolsConfig as T, type RouteItem as U, type DefinePlugin as V, type PluginAPI as W, type PluginLogger as X, type YwkfConfig as Y, type ZustandPluginOptions as Z, defineConfig as a, type OutputConfig as b, type YwkfUserConfig as c, defaultConfig as d, type PluginHooks as e, type PluginConfig as f, analyticsPlugin as g, type BiomePluginOptions as h, biomePlugin as i, type BrowserCheckPluginOptions as j, type BrowserMinVersions as k, browserCheckPlugin as l, type GarfishPluginOptions as m, garfishPlugin as n, getDefaultBiomeConfig as o, i18nPlugin as p, type MockPluginOptions as q, mockPlugin as r, type ReactQueryPluginOptions as s, reactQueryPlugin as t, type TailwindPluginOptions as u, type ThemePluginOptions as v, tailwindPlugin as w, themePlugin as x, type BuildHooks as y, zustandPlugin as z };