@meng-xi/vite-plugin 0.1.0 → 0.1.2
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.
- package/README-en.md +264 -533
- package/README.md +253 -522
- package/dist/common/format/index.cjs +1 -0
- package/dist/common/format/index.d.cts +156 -0
- package/dist/common/format/index.d.mts +156 -0
- package/dist/common/format/index.d.ts +156 -0
- package/dist/common/format/index.mjs +1 -0
- package/dist/common/fs/index.cjs +1 -0
- package/dist/common/fs/index.d.cts +150 -0
- package/dist/common/fs/index.d.mts +150 -0
- package/dist/common/fs/index.d.ts +150 -0
- package/dist/common/fs/index.mjs +1 -0
- package/dist/common/html/index.cjs +2 -0
- package/dist/common/html/index.d.cts +109 -0
- package/dist/common/html/index.d.mts +109 -0
- package/dist/common/html/index.d.ts +109 -0
- package/dist/common/html/index.mjs +2 -0
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +7 -417
- package/dist/common/index.d.mts +7 -417
- package/dist/common/index.d.ts +7 -417
- package/dist/common/index.mjs +1 -1
- package/dist/common/object/index.cjs +1 -0
- package/dist/common/object/index.d.cts +30 -0
- package/dist/common/object/index.d.mts +30 -0
- package/dist/common/object/index.d.ts +30 -0
- package/dist/common/object/index.mjs +1 -0
- package/dist/common/script/index.cjs +1 -0
- package/dist/common/script/index.d.cts +54 -0
- package/dist/common/script/index.d.mts +54 -0
- package/dist/common/script/index.d.ts +54 -0
- package/dist/common/script/index.mjs +1 -0
- package/dist/common/validation/index.cjs +1 -0
- package/dist/common/validation/index.d.cts +93 -0
- package/dist/common/validation/index.d.mts +93 -0
- package/dist/common/validation/index.d.ts +93 -0
- package/dist/common/validation/index.mjs +1 -0
- package/dist/factory/index.cjs +1 -1
- package/dist/factory/index.d.cts +1 -1
- package/dist/factory/index.d.mts +1 -1
- package/dist/factory/index.d.ts +1 -1
- package/dist/factory/index.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +16 -3
- package/dist/index.d.mts +16 -3
- package/dist/index.d.ts +16 -3
- package/dist/index.mjs +1 -1
- package/dist/plugins/buildProgress/index.cjs +2 -0
- package/dist/plugins/buildProgress/index.d.cts +187 -0
- package/dist/plugins/buildProgress/index.d.mts +187 -0
- package/dist/plugins/buildProgress/index.d.ts +187 -0
- package/dist/plugins/buildProgress/index.mjs +2 -0
- package/dist/plugins/compressAssets/index.cjs +1 -0
- package/dist/plugins/compressAssets/index.d.cts +132 -0
- package/dist/plugins/compressAssets/index.d.mts +132 -0
- package/dist/plugins/compressAssets/index.d.ts +132 -0
- package/dist/plugins/compressAssets/index.mjs +1 -0
- package/dist/plugins/copyFile/index.cjs +1 -0
- package/dist/plugins/copyFile/index.d.cts +78 -0
- package/dist/plugins/copyFile/index.d.mts +78 -0
- package/dist/plugins/copyFile/index.d.ts +78 -0
- package/dist/plugins/copyFile/index.mjs +1 -0
- package/dist/plugins/faviconManager/index.cjs +1 -0
- package/dist/plugins/faviconManager/index.d.cts +143 -0
- package/dist/plugins/faviconManager/index.d.mts +143 -0
- package/dist/plugins/faviconManager/index.d.ts +143 -0
- package/dist/plugins/faviconManager/index.mjs +1 -0
- package/dist/plugins/generateRouter/index.cjs +35 -0
- package/dist/plugins/generateRouter/index.d.cts +215 -0
- package/dist/plugins/generateRouter/index.d.mts +215 -0
- package/dist/plugins/generateRouter/index.d.ts +215 -0
- package/dist/plugins/generateRouter/index.mjs +35 -0
- package/dist/plugins/generateVersion/index.cjs +1 -0
- package/dist/plugins/generateVersion/index.d.cts +184 -0
- package/dist/plugins/generateVersion/index.d.mts +184 -0
- package/dist/plugins/generateVersion/index.d.ts +184 -0
- package/dist/plugins/generateVersion/index.mjs +1 -0
- package/dist/plugins/htmlInject/index.cjs +7 -0
- package/dist/plugins/htmlInject/index.d.cts +278 -0
- package/dist/plugins/htmlInject/index.d.mts +278 -0
- package/dist/plugins/htmlInject/index.d.ts +278 -0
- package/dist/plugins/htmlInject/index.mjs +7 -0
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +11 -1714
- package/dist/plugins/index.d.mts +11 -1714
- package/dist/plugins/index.d.ts +11 -1714
- package/dist/plugins/index.mjs +1 -1
- package/dist/plugins/loadingManager/index.cjs +487 -0
- package/dist/plugins/loadingManager/index.d.cts +769 -0
- package/dist/plugins/loadingManager/index.d.mts +769 -0
- package/dist/plugins/loadingManager/index.d.ts +769 -0
- package/dist/plugins/loadingManager/index.mjs +487 -0
- package/dist/plugins/versionUpdateChecker/index.cjs +185 -0
- package/dist/plugins/versionUpdateChecker/index.d.cts +200 -0
- package/dist/plugins/versionUpdateChecker/index.d.mts +200 -0
- package/dist/plugins/versionUpdateChecker/index.d.ts +200 -0
- package/dist/plugins/versionUpdateChecker/index.mjs +185 -0
- package/dist/shared/vite-plugin.Bcg6RW2N.cjs +3 -0
- package/dist/shared/{vite-plugin.CiHfwMiN.d.ts → vite-plugin.DRRlWY8P.d.cts} +50 -0
- package/dist/shared/{vite-plugin.CiHfwMiN.d.cts → vite-plugin.DRRlWY8P.d.mts} +50 -0
- package/dist/shared/{vite-plugin.CiHfwMiN.d.mts → vite-plugin.DRRlWY8P.d.ts} +50 -0
- package/dist/shared/{vite-plugin.B88RyRN8.mjs → vite-plugin.DcExl6jd.mjs} +2 -2
- package/package.json +80 -3
- package/dist/shared/vite-plugin.CawoITTT.cjs +0 -1
- package/dist/shared/vite-plugin.D6Law9Ke.mjs +0 -706
- package/dist/shared/vite-plugin.D8L9KzuW.cjs +0 -706
- package/dist/shared/vite-plugin.DFjf9wFM.mjs +0 -2
- package/dist/shared/vite-plugin.DSb6XzBn.mjs +0 -1
- package/dist/shared/vite-plugin.IGZeStMa.cjs +0 -3
- package/dist/shared/vite-plugin.Tab4qcIM.cjs +0 -2
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { BasePluginOptions, PluginFactory } from '../../factory/index.cjs';
|
|
2
|
+
import 'vite';
|
|
3
|
+
import '../../shared/vite-plugin.CLr0ttuO.cjs';
|
|
4
|
+
import '../../shared/vite-plugin.DRRlWY8P.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 图标配置项接口
|
|
8
|
+
*
|
|
9
|
+
* @interface Icon
|
|
10
|
+
*/
|
|
11
|
+
interface Icon {
|
|
12
|
+
/**
|
|
13
|
+
* 图标关系类型
|
|
14
|
+
*/
|
|
15
|
+
rel: string;
|
|
16
|
+
/**
|
|
17
|
+
* 图标 URL
|
|
18
|
+
*/
|
|
19
|
+
href: string;
|
|
20
|
+
/**
|
|
21
|
+
* 图标尺寸
|
|
22
|
+
*/
|
|
23
|
+
sizes?: string;
|
|
24
|
+
/**
|
|
25
|
+
* 图标 MIME 类型
|
|
26
|
+
*/
|
|
27
|
+
type?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 图标文件复制配置选项接口
|
|
31
|
+
*
|
|
32
|
+
* @interface CopyOptions
|
|
33
|
+
*/
|
|
34
|
+
interface CopyOptions {
|
|
35
|
+
/**
|
|
36
|
+
* 图标源文件目录,用于复制图标到打包目录
|
|
37
|
+
*
|
|
38
|
+
* @example 'src/assets/icons'
|
|
39
|
+
*/
|
|
40
|
+
sourceDir: string;
|
|
41
|
+
/**
|
|
42
|
+
* 图标目标目录(打包目录),用于复制图标到打包目录
|
|
43
|
+
*
|
|
44
|
+
* @example 'dist/assets/icons'
|
|
45
|
+
*/
|
|
46
|
+
targetDir: string;
|
|
47
|
+
/**
|
|
48
|
+
* 是否覆盖同名文件
|
|
49
|
+
*
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
overwrite?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* 是否支持递归复制
|
|
55
|
+
*
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
recursive?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 网站图标管理插件的配置选项接口
|
|
62
|
+
*
|
|
63
|
+
* @interface FaviconManagerOptions
|
|
64
|
+
*/
|
|
65
|
+
interface FaviconManagerOptions extends BasePluginOptions {
|
|
66
|
+
/**
|
|
67
|
+
* 图标文件的基础路径,默认为根路径 '/'
|
|
68
|
+
*
|
|
69
|
+
* @default '/'
|
|
70
|
+
* @example '/assets'
|
|
71
|
+
*/
|
|
72
|
+
base?: string;
|
|
73
|
+
/**
|
|
74
|
+
* 图标的完整 URL,如果提供则优先使用(覆盖 base + favicon.ico)
|
|
75
|
+
*
|
|
76
|
+
* @example 'https://example.com/favicon.ico'
|
|
77
|
+
*/
|
|
78
|
+
url?: string;
|
|
79
|
+
/**
|
|
80
|
+
* 自定义的完整 link 标签 HTML,如果提供则优先使用(覆盖 url 和 base)
|
|
81
|
+
*
|
|
82
|
+
* @example '<link rel="icon" href="/favicon.svg" type="image/svg+xml" />'
|
|
83
|
+
*/
|
|
84
|
+
link?: string;
|
|
85
|
+
/**
|
|
86
|
+
* 自定义图标数组,支持多种图标格式和尺寸
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* [
|
|
90
|
+
* { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
|
|
91
|
+
* { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
|
|
92
|
+
* { rel: 'icon', href: '/favicon-16x16.png', sizes: '16x16', type: 'image/png' }
|
|
93
|
+
* ]
|
|
94
|
+
*/
|
|
95
|
+
icons?: Icon[];
|
|
96
|
+
/**
|
|
97
|
+
* 图标文件复制配置选项
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* 当此对象存在时,才会开启图标文件复制功能
|
|
101
|
+
*/
|
|
102
|
+
copyOptions?: CopyOptions;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 网站图标管理插件
|
|
107
|
+
*
|
|
108
|
+
* @param options - 插件配置选项,可以是字符串形式的 base 路径或完整的配置对象
|
|
109
|
+
* @returns Vite 插件实例
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // 基本使用
|
|
114
|
+
* faviconManager() // 使用默认配置
|
|
115
|
+
*
|
|
116
|
+
* // 使用字符串配置 base 路径
|
|
117
|
+
* faviconManager('/assets')
|
|
118
|
+
*
|
|
119
|
+
* // 使用完整配置
|
|
120
|
+
* faviconManager({
|
|
121
|
+
* base: '/assets',
|
|
122
|
+
* icons: [
|
|
123
|
+
* { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
|
|
124
|
+
* { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' }
|
|
125
|
+
* ],
|
|
126
|
+
* copyOptions: {
|
|
127
|
+
* sourceDir: 'src/assets/icons',
|
|
128
|
+
* targetDir: 'dist/assets/icons'
|
|
129
|
+
* }
|
|
130
|
+
* })
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @remarks
|
|
134
|
+
* 该插件在构建过程中:
|
|
135
|
+
* 1. 将网站图标(favicon)的 link 标签注入到 HTML 文件的 `<head>` 中
|
|
136
|
+
* 2. 如果配置了 copyOptions,将图标文件复制到目标目录
|
|
137
|
+
*
|
|
138
|
+
* 支持自定义图标链接、图标数组配置以及图标文件复制功能。
|
|
139
|
+
*/
|
|
140
|
+
declare const faviconManager: PluginFactory<FaviconManagerOptions, string | FaviconManagerOptions>;
|
|
141
|
+
|
|
142
|
+
export { faviconManager };
|
|
143
|
+
export type { FaviconManagerOptions, Icon };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { BasePluginOptions, PluginFactory } from '../../factory/index.mjs';
|
|
2
|
+
import 'vite';
|
|
3
|
+
import '../../shared/vite-plugin.CLr0ttuO.mjs';
|
|
4
|
+
import '../../shared/vite-plugin.DRRlWY8P.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 图标配置项接口
|
|
8
|
+
*
|
|
9
|
+
* @interface Icon
|
|
10
|
+
*/
|
|
11
|
+
interface Icon {
|
|
12
|
+
/**
|
|
13
|
+
* 图标关系类型
|
|
14
|
+
*/
|
|
15
|
+
rel: string;
|
|
16
|
+
/**
|
|
17
|
+
* 图标 URL
|
|
18
|
+
*/
|
|
19
|
+
href: string;
|
|
20
|
+
/**
|
|
21
|
+
* 图标尺寸
|
|
22
|
+
*/
|
|
23
|
+
sizes?: string;
|
|
24
|
+
/**
|
|
25
|
+
* 图标 MIME 类型
|
|
26
|
+
*/
|
|
27
|
+
type?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 图标文件复制配置选项接口
|
|
31
|
+
*
|
|
32
|
+
* @interface CopyOptions
|
|
33
|
+
*/
|
|
34
|
+
interface CopyOptions {
|
|
35
|
+
/**
|
|
36
|
+
* 图标源文件目录,用于复制图标到打包目录
|
|
37
|
+
*
|
|
38
|
+
* @example 'src/assets/icons'
|
|
39
|
+
*/
|
|
40
|
+
sourceDir: string;
|
|
41
|
+
/**
|
|
42
|
+
* 图标目标目录(打包目录),用于复制图标到打包目录
|
|
43
|
+
*
|
|
44
|
+
* @example 'dist/assets/icons'
|
|
45
|
+
*/
|
|
46
|
+
targetDir: string;
|
|
47
|
+
/**
|
|
48
|
+
* 是否覆盖同名文件
|
|
49
|
+
*
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
overwrite?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* 是否支持递归复制
|
|
55
|
+
*
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
recursive?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 网站图标管理插件的配置选项接口
|
|
62
|
+
*
|
|
63
|
+
* @interface FaviconManagerOptions
|
|
64
|
+
*/
|
|
65
|
+
interface FaviconManagerOptions extends BasePluginOptions {
|
|
66
|
+
/**
|
|
67
|
+
* 图标文件的基础路径,默认为根路径 '/'
|
|
68
|
+
*
|
|
69
|
+
* @default '/'
|
|
70
|
+
* @example '/assets'
|
|
71
|
+
*/
|
|
72
|
+
base?: string;
|
|
73
|
+
/**
|
|
74
|
+
* 图标的完整 URL,如果提供则优先使用(覆盖 base + favicon.ico)
|
|
75
|
+
*
|
|
76
|
+
* @example 'https://example.com/favicon.ico'
|
|
77
|
+
*/
|
|
78
|
+
url?: string;
|
|
79
|
+
/**
|
|
80
|
+
* 自定义的完整 link 标签 HTML,如果提供则优先使用(覆盖 url 和 base)
|
|
81
|
+
*
|
|
82
|
+
* @example '<link rel="icon" href="/favicon.svg" type="image/svg+xml" />'
|
|
83
|
+
*/
|
|
84
|
+
link?: string;
|
|
85
|
+
/**
|
|
86
|
+
* 自定义图标数组,支持多种图标格式和尺寸
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* [
|
|
90
|
+
* { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
|
|
91
|
+
* { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
|
|
92
|
+
* { rel: 'icon', href: '/favicon-16x16.png', sizes: '16x16', type: 'image/png' }
|
|
93
|
+
* ]
|
|
94
|
+
*/
|
|
95
|
+
icons?: Icon[];
|
|
96
|
+
/**
|
|
97
|
+
* 图标文件复制配置选项
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* 当此对象存在时,才会开启图标文件复制功能
|
|
101
|
+
*/
|
|
102
|
+
copyOptions?: CopyOptions;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 网站图标管理插件
|
|
107
|
+
*
|
|
108
|
+
* @param options - 插件配置选项,可以是字符串形式的 base 路径或完整的配置对象
|
|
109
|
+
* @returns Vite 插件实例
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // 基本使用
|
|
114
|
+
* faviconManager() // 使用默认配置
|
|
115
|
+
*
|
|
116
|
+
* // 使用字符串配置 base 路径
|
|
117
|
+
* faviconManager('/assets')
|
|
118
|
+
*
|
|
119
|
+
* // 使用完整配置
|
|
120
|
+
* faviconManager({
|
|
121
|
+
* base: '/assets',
|
|
122
|
+
* icons: [
|
|
123
|
+
* { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
|
|
124
|
+
* { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' }
|
|
125
|
+
* ],
|
|
126
|
+
* copyOptions: {
|
|
127
|
+
* sourceDir: 'src/assets/icons',
|
|
128
|
+
* targetDir: 'dist/assets/icons'
|
|
129
|
+
* }
|
|
130
|
+
* })
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @remarks
|
|
134
|
+
* 该插件在构建过程中:
|
|
135
|
+
* 1. 将网站图标(favicon)的 link 标签注入到 HTML 文件的 `<head>` 中
|
|
136
|
+
* 2. 如果配置了 copyOptions,将图标文件复制到目标目录
|
|
137
|
+
*
|
|
138
|
+
* 支持自定义图标链接、图标数组配置以及图标文件复制功能。
|
|
139
|
+
*/
|
|
140
|
+
declare const faviconManager: PluginFactory<FaviconManagerOptions, string | FaviconManagerOptions>;
|
|
141
|
+
|
|
142
|
+
export { faviconManager };
|
|
143
|
+
export type { FaviconManagerOptions, Icon };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { BasePluginOptions, PluginFactory } from '../../factory/index.js';
|
|
2
|
+
import 'vite';
|
|
3
|
+
import '../../shared/vite-plugin.CLr0ttuO.js';
|
|
4
|
+
import '../../shared/vite-plugin.DRRlWY8P.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 图标配置项接口
|
|
8
|
+
*
|
|
9
|
+
* @interface Icon
|
|
10
|
+
*/
|
|
11
|
+
interface Icon {
|
|
12
|
+
/**
|
|
13
|
+
* 图标关系类型
|
|
14
|
+
*/
|
|
15
|
+
rel: string;
|
|
16
|
+
/**
|
|
17
|
+
* 图标 URL
|
|
18
|
+
*/
|
|
19
|
+
href: string;
|
|
20
|
+
/**
|
|
21
|
+
* 图标尺寸
|
|
22
|
+
*/
|
|
23
|
+
sizes?: string;
|
|
24
|
+
/**
|
|
25
|
+
* 图标 MIME 类型
|
|
26
|
+
*/
|
|
27
|
+
type?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 图标文件复制配置选项接口
|
|
31
|
+
*
|
|
32
|
+
* @interface CopyOptions
|
|
33
|
+
*/
|
|
34
|
+
interface CopyOptions {
|
|
35
|
+
/**
|
|
36
|
+
* 图标源文件目录,用于复制图标到打包目录
|
|
37
|
+
*
|
|
38
|
+
* @example 'src/assets/icons'
|
|
39
|
+
*/
|
|
40
|
+
sourceDir: string;
|
|
41
|
+
/**
|
|
42
|
+
* 图标目标目录(打包目录),用于复制图标到打包目录
|
|
43
|
+
*
|
|
44
|
+
* @example 'dist/assets/icons'
|
|
45
|
+
*/
|
|
46
|
+
targetDir: string;
|
|
47
|
+
/**
|
|
48
|
+
* 是否覆盖同名文件
|
|
49
|
+
*
|
|
50
|
+
* @default true
|
|
51
|
+
*/
|
|
52
|
+
overwrite?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* 是否支持递归复制
|
|
55
|
+
*
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
recursive?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 网站图标管理插件的配置选项接口
|
|
62
|
+
*
|
|
63
|
+
* @interface FaviconManagerOptions
|
|
64
|
+
*/
|
|
65
|
+
interface FaviconManagerOptions extends BasePluginOptions {
|
|
66
|
+
/**
|
|
67
|
+
* 图标文件的基础路径,默认为根路径 '/'
|
|
68
|
+
*
|
|
69
|
+
* @default '/'
|
|
70
|
+
* @example '/assets'
|
|
71
|
+
*/
|
|
72
|
+
base?: string;
|
|
73
|
+
/**
|
|
74
|
+
* 图标的完整 URL,如果提供则优先使用(覆盖 base + favicon.ico)
|
|
75
|
+
*
|
|
76
|
+
* @example 'https://example.com/favicon.ico'
|
|
77
|
+
*/
|
|
78
|
+
url?: string;
|
|
79
|
+
/**
|
|
80
|
+
* 自定义的完整 link 标签 HTML,如果提供则优先使用(覆盖 url 和 base)
|
|
81
|
+
*
|
|
82
|
+
* @example '<link rel="icon" href="/favicon.svg" type="image/svg+xml" />'
|
|
83
|
+
*/
|
|
84
|
+
link?: string;
|
|
85
|
+
/**
|
|
86
|
+
* 自定义图标数组,支持多种图标格式和尺寸
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* [
|
|
90
|
+
* { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
|
|
91
|
+
* { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' },
|
|
92
|
+
* { rel: 'icon', href: '/favicon-16x16.png', sizes: '16x16', type: 'image/png' }
|
|
93
|
+
* ]
|
|
94
|
+
*/
|
|
95
|
+
icons?: Icon[];
|
|
96
|
+
/**
|
|
97
|
+
* 图标文件复制配置选项
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* 当此对象存在时,才会开启图标文件复制功能
|
|
101
|
+
*/
|
|
102
|
+
copyOptions?: CopyOptions;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 网站图标管理插件
|
|
107
|
+
*
|
|
108
|
+
* @param options - 插件配置选项,可以是字符串形式的 base 路径或完整的配置对象
|
|
109
|
+
* @returns Vite 插件实例
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // 基本使用
|
|
114
|
+
* faviconManager() // 使用默认配置
|
|
115
|
+
*
|
|
116
|
+
* // 使用字符串配置 base 路径
|
|
117
|
+
* faviconManager('/assets')
|
|
118
|
+
*
|
|
119
|
+
* // 使用完整配置
|
|
120
|
+
* faviconManager({
|
|
121
|
+
* base: '/assets',
|
|
122
|
+
* icons: [
|
|
123
|
+
* { rel: 'icon', href: '/favicon.svg', type: 'image/svg+xml' },
|
|
124
|
+
* { rel: 'icon', href: '/favicon-32x32.png', sizes: '32x32', type: 'image/png' }
|
|
125
|
+
* ],
|
|
126
|
+
* copyOptions: {
|
|
127
|
+
* sourceDir: 'src/assets/icons',
|
|
128
|
+
* targetDir: 'dist/assets/icons'
|
|
129
|
+
* }
|
|
130
|
+
* })
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @remarks
|
|
134
|
+
* 该插件在构建过程中:
|
|
135
|
+
* 1. 将网站图标(favicon)的 link 标签注入到 HTML 文件的 `<head>` 中
|
|
136
|
+
* 2. 如果配置了 copyOptions,将图标文件复制到目标目录
|
|
137
|
+
*
|
|
138
|
+
* 支持自定义图标链接、图标数组配置以及图标文件复制功能。
|
|
139
|
+
*/
|
|
140
|
+
declare const faviconManager: PluginFactory<FaviconManagerOptions, string | FaviconManagerOptions>;
|
|
141
|
+
|
|
142
|
+
export { faviconManager };
|
|
143
|
+
export type { FaviconManagerOptions, Icon };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createPluginFactory as n,BasePlugin as a}from"../../factory/index.mjs";import{checkSourceExists as c,copySourceToTarget as l}from"../../common/fs/index.mjs";import{V as g}from"../../shared/vite-plugin.DcExl6jd.mjs";import{injectBeforeTag as p}from"../../common/html/index.mjs";import"../../logger/index.mjs";import"../../common/object/index.mjs";import"fs";import"path";function F(u){const i=[];if(u.link)return[];if(u.icons&&u.icons.length>0)for(const e of u.icons){const t={rel:e.rel,href:e.href};e.sizes&&(t.sizes=e.sizes),e.type&&(t.type=e.type),i.push({tag:"link",attrs:t,injectTo:"head"})}else if(u.url)i.push({tag:"link",attrs:{rel:"icon",href:u.url},injectTo:"head"});else{const e=u.base||"/",t=e.endsWith("/")?`${e}favicon.ico`:`${e}/favicon.ico`;i.push({tag:"link",attrs:{rel:"icon",href:t},injectTo:"head"})}return i}class h extends a{getDefaultOptions(){return{base:"/"}}validateOptions(){this.validator.field("base").string().field("url").string().field("link").string().field("icons").array(),this.options?.copyOptions&&(this.validator.field("copyOptions").object(),new g(this.options.copyOptions).field("sourceDir").required().string().field("targetDir").required().string().field("overwrite").boolean().field("recursive").boolean().validate()),this.validator.validate()}getPluginName(){return"favicon-manager"}getIconTagDescriptors(){if(!this.options.enabled)return this.logger.info("\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u56FE\u6807\u6CE8\u5165"),[];const i=F(this.options);return i.length>0&&this.logger.success(`\u6210\u529F\u6CE8\u5165 ${i.length} \u4E2A\u56FE\u6807\u6807\u7B7E\u5230 HTML \u6587\u4EF6`),i}injectCustomLinkTag(i){if(!this.options.enabled||!this.options.link)return i;const e=this.options.link,t=p(i,"</head>",e);return t.injected?(this.logger.success("\u6210\u529F\u6CE8\u5165\u81EA\u5B9A\u4E49\u56FE\u6807\u6807\u7B7E\u5230 HTML \u6587\u4EF6"),this.logger.info(` - ${e}`),t.html):(this.logger.warn("\u672A\u627E\u5230 </head> \u6807\u7B7E\uFF0C\u8DF3\u8FC7\u56FE\u6807\u6CE8\u5165"),i)}async copyFiles(){if(!this.options.enabled){this.logger.info("\u63D2\u4EF6\u5DF2\u7981\u7528\uFF0C\u8DF3\u8FC7\u6587\u4EF6\u590D\u5236");return}const{copyOptions:i}=this.options;if(!i)return;const{sourceDir:e,targetDir:t,overwrite:s=!0,recursive:o=!0}=i;await c(e);const r=await l(e,t,{recursive:o,overwrite:s,incremental:!0});this.logger.success(`\u56FE\u6807\u6587\u4EF6\u590D\u5236\u6210\u529F\uFF1A\u4ECE ${e} \u5230 ${t}`,`\u590D\u5236\u4E86 ${r.copiedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8DF3\u8FC7\u4E86 ${r.skippedFiles} \u4E2A\u6587\u4EF6\uFF0C\u8017\u65F6 ${r.executionTime}ms`)}addPluginHooks(i){i.transformIndexHtml={order:"pre",handler:e=>{if(this.options.link)return this.injectCustomLinkTag(e);const t=this.getIconTagDescriptors();return t.length>0?{html:e,tags:t}:e}},i.writeBundle=async()=>{await this.safeExecute(()=>this.copyFiles(),"\u56FE\u6807\u6587\u4EF6\u590D\u5236")}}}const f=n(h,u=>typeof u=="string"?{base:u}:u||{});export{f as faviconManager};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";const factory_index=require("../../factory/index.cjs"),common_fs_index=require("../../common/fs/index.cjs"),common_format_index=require("../../common/format/index.cjs"),u=require("path"),s=require("fs");require("../../logger/index.cjs"),require("../../common/object/index.cjs"),require("../../shared/vite-plugin.Bcg6RW2N.cjs"),require("crypto");class R extends factory_index.BasePlugin{projectRoot=process.cwd();tabBarPages=new Set;watcher=null;getDefaultOptions(){return{pagesJsonPath:"src/pages.json",outputPath:"src/router.config.ts",outputFormat:"ts",nameStrategy:"camelCase",includeSubPackages:!0,watch:!0,exportTypes:!0,preserveRouteChanges:!0,metaMapping:{navigationBarTitleText:"title",requireAuth:"requireAuth"}}}validateOptions(){if(this.validator.field("pagesJsonPath").string().field("outputPath").string().field("outputFormat").enum(["ts","js"]).field("nameStrategy").enum(["path","camelCase","pascalCase","custom"]).validate(),this.options.nameStrategy==="custom"&&!this.options.customNameGenerator)throw new Error("\u5F53 nameStrategy \u4E3A custom \u65F6\uFF0C\u5FC5\u987B\u63D0\u4F9B customNameGenerator")}getPluginName(){return"generate-router"}generateRouteName(e){switch(this.options.nameStrategy){case"path":return e.replace(/\//g,"_").replace(/^_/,"");case"camelCase":return common_format_index.toCamelCase(e);case"pascalCase":return common_format_index.toPascalCase(e);case"custom":return this.options.customNameGenerator(e);default:return common_format_index.toCamelCase(e)}}extractMeta(e,a){const t={},r=e.style||{},o=this.options.metaMapping||{};for(const[n,i]of Object.entries(o))r[n]!==void 0&&(t[i]=r[n]);return this.tabBarPages.has(a)&&(t.isTab=!0),t}parsePageToRoute(e,a=""){const t=a?`/${a}/${e.path}`:`/${e.path}`,r=this.generateRouteName(t),o=this.extractMeta(e,t.replace(/^\//,"")),n={path:t,name:r};return Object.keys(o).length>0&&(n.meta=o),n}parsePagesJson(e){const a=[];if(!e.pages||!Array.isArray(e.pages)||e.pages.length===0)return this.logger.warn("pages.json \u4E2D\u6CA1\u6709\u6709\u6548\u7684\u9875\u9762\u914D\u7F6E"),a;if(this.tabBarPages.clear(),e.tabBar?.list)for(const t of e.tabBar.list)this.tabBarPages.add(t.pagePath);for(const t of e.pages)a.push(this.parsePageToRoute(t));if(this.options.includeSubPackages&&e.subPackages){for(const t of e.subPackages)if(t.pages&&Array.isArray(t.pages))for(const r of t.pages)a.push(this.parsePageToRoute(r,t.root))}return a}generateTypeDefinitions(){return!this.options.exportTypes||this.options.outputFormat==="js"?"":`
|
|
2
|
+
/**
|
|
3
|
+
* \u8DEF\u7531\u5143\u4FE1\u606F
|
|
4
|
+
*/
|
|
5
|
+
export interface RouteMeta {
|
|
6
|
+
/** \u9875\u9762\u6807\u9898 */
|
|
7
|
+
title?: string
|
|
8
|
+
/** \u662F\u5426\u4E3ATabBar\u9875\u9762 */
|
|
9
|
+
isTab?: boolean
|
|
10
|
+
/** \u662F\u5426\u9700\u8981\u767B\u5F55 */
|
|
11
|
+
requireAuth?: boolean
|
|
12
|
+
/** \u81EA\u5B9A\u4E49\u6269\u5C55\u5B57\u6BB5 */
|
|
13
|
+
[key: string]: unknown
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* \u8DEF\u7531\u914D\u7F6E\u9879
|
|
18
|
+
*/
|
|
19
|
+
export interface RouteConfig {
|
|
20
|
+
/** \u8DEF\u7531\u8DEF\u5F84 */
|
|
21
|
+
path: string
|
|
22
|
+
/** \u8DEF\u7531\u540D\u79F0\uFF08\u7528\u4E8E\u547D\u540D\u8DEF\u7531\u5BFC\u822A\uFF09 */
|
|
23
|
+
name?: string
|
|
24
|
+
/** \u8DEF\u7531\u5143\u4FE1\u606F */
|
|
25
|
+
meta?: RouteMeta
|
|
26
|
+
}
|
|
27
|
+
`}generateFileContent(e){const a=this.generateTypeDefinitions(),t=this.options.outputFormat==="ts",r=JSON.stringify(e,null," ").replace(/"(\w+)":/g,"$1:").replace(/: "([^"]+)"/g,": '$1'");return`${a}
|
|
28
|
+
/**
|
|
29
|
+
* \u8DEF\u7531\u914D\u7F6E\u5217\u8868
|
|
30
|
+
* @description \u7531 pages.json \u81EA\u52A8\u751F\u6210
|
|
31
|
+
*/
|
|
32
|
+
export const routes${t?": RouteConfig[]":""} = ${r}
|
|
33
|
+
|
|
34
|
+
export default routes
|
|
35
|
+
`}async readPagesJson(){const e=u.resolve(this.projectRoot,this.options.pagesJsonPath);if(!s.existsSync(e))return this.logger.warn(`pages.json \u6587\u4EF6\u4E0D\u5B58\u5728: ${e}`),null;try{const a=await common_fs_index.readFileContent(e),t=common_format_index.stripJsonComments(a);return JSON.parse(t)}catch(a){return this.logger.error(`\u89E3\u6790 pages.json \u5931\u8D25: ${a.message}`),null}}extractExistingRoutes(e){const a=new Map,t=e.match(/export const routes[^=]*=\s*(\[[\s\S]*?\](?=\s*\n|\s*$|\s*\/\/))/);if(!t)return a;try{let r=t[1].replace(/(\w+)(?=\s*:)/g,'"$1"').replace(/'([^']*)'/g,'"$1"').replace(/,\s*([\]\}])/g,"$1");const o=JSON.parse(r);for(const n of o)n.path&&a.set(n.path,n)}catch{this.logger.warn("\u89E3\u6790\u73B0\u6709 routes \u914D\u7F6E\u5931\u8D25\uFF0C\u5C06\u5B8C\u5168\u91CD\u65B0\u751F\u6210")}return a}mergeRoutes(e,a){return e.map(t=>{const r=a.get(t.path);if(!r)return t;const o={};return t.meta&&Object.assign(o,t.meta),r.meta&&Object.assign(o,r.meta),{...r,path:t.path,meta:Object.keys(o).length>0?o:void 0}})}async generateRouterConfig(){const e=await this.readPagesJson();if(!e)return;let a=this.parsePagesJson(e);const t=u.resolve(this.projectRoot,this.options.outputPath);if(this.options.preserveRouteChanges&&s.existsSync(t))try{const o=await common_fs_index.readFileContent(t),n=this.extractExistingRoutes(o);n.size>0&&(a=this.mergeRoutes(a,n),this.logger.info("\u5DF2\u5408\u5E76\u7528\u6237\u5BF9\u8DEF\u7531\u914D\u7F6E\u7684\u4FEE\u6539"))}catch{}const r=this.generateFileContent(a);await common_fs_index.writeFileContent(t,r),this.logger.success(`\u8DEF\u7531\u914D\u7F6E\u6587\u4EF6\u5DF2\u751F\u6210: ${t}`),this.logger.info(`\u5171\u751F\u6210 ${a.length} \u6761\u8DEF\u7531\u914D\u7F6E`)}startWatching(){if(!this.options.watch)return;const e=u.resolve(this.projectRoot,this.options.pagesJsonPath);s.existsSync(e)&&(this.watcher=s.watch(e,async a=>{a==="change"&&(this.logger.info("\u68C0\u6D4B\u5230 pages.json \u53D8\u5316\uFF0C\u91CD\u65B0\u751F\u6210\u8DEF\u7531\u914D\u7F6E..."),await this.safeExecute(()=>this.generateRouterConfig(),"\u91CD\u65B0\u751F\u6210\u8DEF\u7531\u914D\u7F6E"))}),this.logger.info(`\u6B63\u5728\u76D1\u542C pages.json \u53D8\u5316: ${e}`))}stopWatching(){this.watcher&&(this.watcher.close(),this.watcher=null)}addPluginHooks(e){e.configResolved=async a=>{this.projectRoot=a.root,await this.safeExecute(()=>this.generateRouterConfig(),"\u751F\u6210\u8DEF\u7531\u914D\u7F6E"),a.command==="serve"&&this.startWatching()}}destroy(){super.destroy(),this.stopWatching()}}const generateRouter=factory_index.createPluginFactory(R);exports.generateRouter=generateRouter;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { BasePluginOptions, PluginFactory } from '../../factory/index.cjs';
|
|
2
|
+
import 'vite';
|
|
3
|
+
import '../../shared/vite-plugin.CLr0ttuO.cjs';
|
|
4
|
+
import '../../shared/vite-plugin.DRRlWY8P.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 路由元信息
|
|
8
|
+
*/
|
|
9
|
+
interface RouteMeta {
|
|
10
|
+
/** 页面标题 */
|
|
11
|
+
title?: string;
|
|
12
|
+
/** 是否为TabBar页面 */
|
|
13
|
+
isTab?: boolean;
|
|
14
|
+
/** 是否需要登录 */
|
|
15
|
+
requireAuth?: boolean;
|
|
16
|
+
/** 自定义扩展字段 */
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 路由配置项
|
|
21
|
+
*/
|
|
22
|
+
interface RouteConfig {
|
|
23
|
+
/** 路由路径 */
|
|
24
|
+
path: string;
|
|
25
|
+
/** 路由名称(用于命名路由导航) */
|
|
26
|
+
name?: string;
|
|
27
|
+
/** 路由元信息 */
|
|
28
|
+
meta?: RouteMeta;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* uni-app pages.json 中的页面配置项
|
|
32
|
+
*/
|
|
33
|
+
interface UniAppPageConfig {
|
|
34
|
+
/** 页面路径 */
|
|
35
|
+
path: string;
|
|
36
|
+
/** 页面样式 */
|
|
37
|
+
style?: {
|
|
38
|
+
/** 导航栏标题 */
|
|
39
|
+
navigationBarTitleText?: string;
|
|
40
|
+
/** 是否需要登录 */
|
|
41
|
+
requireAuth?: boolean;
|
|
42
|
+
/** 其他自定义属性 */
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
};
|
|
45
|
+
/** 其他属性 */
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* uni-app pages.json 中的 tabBar 配置
|
|
50
|
+
*/
|
|
51
|
+
interface UniAppTabBarConfig {
|
|
52
|
+
/** tabBar 列表 */
|
|
53
|
+
list?: Array<{
|
|
54
|
+
/** 页面路径 */
|
|
55
|
+
pagePath: string;
|
|
56
|
+
/** 文字 */
|
|
57
|
+
text?: string;
|
|
58
|
+
/** 图标路径 */
|
|
59
|
+
iconPath?: string;
|
|
60
|
+
/** 选中图标路径 */
|
|
61
|
+
selectedIconPath?: string;
|
|
62
|
+
}>;
|
|
63
|
+
/** 其他属性 */
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* uni-app pages.json 结构
|
|
68
|
+
*/
|
|
69
|
+
interface UniAppPagesJson {
|
|
70
|
+
/** 页面列表 */
|
|
71
|
+
pages: UniAppPageConfig[];
|
|
72
|
+
/** 子包 */
|
|
73
|
+
subPackages?: Array<{
|
|
74
|
+
root: string;
|
|
75
|
+
pages: UniAppPageConfig[];
|
|
76
|
+
}>;
|
|
77
|
+
/** tabBar 配置 */
|
|
78
|
+
tabBar?: UniAppTabBarConfig;
|
|
79
|
+
/** 全局样式 */
|
|
80
|
+
globalStyle?: Record<string, unknown>;
|
|
81
|
+
/** 其他属性 */
|
|
82
|
+
[key: string]: unknown;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 输出文件格式类型
|
|
86
|
+
*/
|
|
87
|
+
type OutputFormat = 'ts' | 'js';
|
|
88
|
+
/**
|
|
89
|
+
* 路由名称生成策略
|
|
90
|
+
*/
|
|
91
|
+
type NameStrategy = 'path' | 'camelCase' | 'pascalCase' | 'custom';
|
|
92
|
+
/**
|
|
93
|
+
* 生成路由配置插件选项
|
|
94
|
+
*/
|
|
95
|
+
interface GenerateRouterOptions extends BasePluginOptions {
|
|
96
|
+
/**
|
|
97
|
+
* pages.json 文件路径(相对于项目根目录)
|
|
98
|
+
*
|
|
99
|
+
* @default 'src/pages.json'
|
|
100
|
+
*/
|
|
101
|
+
pagesJsonPath?: string;
|
|
102
|
+
/**
|
|
103
|
+
* 输出文件路径(相对于项目根目录)
|
|
104
|
+
*
|
|
105
|
+
* @default 'src/router.config.ts'
|
|
106
|
+
*/
|
|
107
|
+
outputPath?: string;
|
|
108
|
+
/**
|
|
109
|
+
* 输出文件格式
|
|
110
|
+
*
|
|
111
|
+
* @default 'ts'
|
|
112
|
+
*/
|
|
113
|
+
outputFormat?: OutputFormat;
|
|
114
|
+
/**
|
|
115
|
+
* 路由名称生成策略
|
|
116
|
+
*
|
|
117
|
+
* @default 'camelCase'
|
|
118
|
+
*/
|
|
119
|
+
nameStrategy?: NameStrategy;
|
|
120
|
+
/**
|
|
121
|
+
* 自定义路由名称生成函数
|
|
122
|
+
*
|
|
123
|
+
* @param path - 页面路径
|
|
124
|
+
* @returns 路由名称
|
|
125
|
+
*/
|
|
126
|
+
customNameGenerator?: (path: string) => string;
|
|
127
|
+
/**
|
|
128
|
+
* 是否包含子包路由
|
|
129
|
+
*
|
|
130
|
+
* @default true
|
|
131
|
+
*/
|
|
132
|
+
includeSubPackages?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* 是否监听 pages.json 变化并自动重新生成
|
|
135
|
+
*
|
|
136
|
+
* @default true
|
|
137
|
+
*/
|
|
138
|
+
watch?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* 额外的元信息字段映射
|
|
141
|
+
*
|
|
142
|
+
* @description 将 pages.json 中 style 的字段映射到 meta 中
|
|
143
|
+
* @example { 'navigationBarTitleText': 'title', 'requireAuth': 'requireAuth' }
|
|
144
|
+
*/
|
|
145
|
+
metaMapping?: Record<string, string>;
|
|
146
|
+
/**
|
|
147
|
+
* 是否导出类型定义
|
|
148
|
+
*
|
|
149
|
+
* @default true
|
|
150
|
+
*/
|
|
151
|
+
exportTypes?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* 是否保留用户对 routes 配置的修改
|
|
154
|
+
*
|
|
155
|
+
* @description 开启后,用户在 routes 数组中修改的字段将被保留
|
|
156
|
+
* @default true
|
|
157
|
+
*/
|
|
158
|
+
preserveRouteChanges?: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 生成路由配置插件
|
|
163
|
+
*
|
|
164
|
+
* @param {GenerateRouterOptions} options - 插件配置选项
|
|
165
|
+
* @returns {Plugin} 一个 Vite 插件实例
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* // 基本使用 - 使用默认配置
|
|
170
|
+
* generateRouter()
|
|
171
|
+
*
|
|
172
|
+
* // 自定义 pages.json 路径
|
|
173
|
+
* generateRouter({
|
|
174
|
+
* pagesJsonPath: 'pages.json'
|
|
175
|
+
* })
|
|
176
|
+
*
|
|
177
|
+
* // 输出 JavaScript 文件
|
|
178
|
+
* generateRouter({
|
|
179
|
+
* outputFormat: 'js',
|
|
180
|
+
* outputPath: 'src/router.config.js'
|
|
181
|
+
* })
|
|
182
|
+
*
|
|
183
|
+
* // 使用帕斯卡命名策略
|
|
184
|
+
* generateRouter({
|
|
185
|
+
* nameStrategy: 'pascalCase'
|
|
186
|
+
* })
|
|
187
|
+
*
|
|
188
|
+
* // 自定义路由名称生成
|
|
189
|
+
* generateRouter({
|
|
190
|
+
* nameStrategy: 'custom',
|
|
191
|
+
* customNameGenerator: (path) => `route_${path.replace(/\//g, '_')}`
|
|
192
|
+
* })
|
|
193
|
+
*
|
|
194
|
+
* // 自定义元信息映射
|
|
195
|
+
* generateRouter({
|
|
196
|
+
* metaMapping: {
|
|
197
|
+
* navigationBarTitleText: 'title',
|
|
198
|
+
* requireAuth: 'requireAuth',
|
|
199
|
+
* customField: 'custom'
|
|
200
|
+
* }
|
|
201
|
+
* })
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @remarks
|
|
205
|
+
* 该插件会读取 uni-app 项目的 pages.json 文件,自动生成路由配置文件:
|
|
206
|
+
* - 支持主包和子包页面
|
|
207
|
+
* - 自动识别 tabBar 页面
|
|
208
|
+
* - 支持多种路由名称生成策略
|
|
209
|
+
* - 支持自定义元信息字段映射
|
|
210
|
+
* - 开发模式下自动监听 pages.json 变化并重新生成
|
|
211
|
+
*/
|
|
212
|
+
declare const generateRouter: PluginFactory<GenerateRouterOptions, GenerateRouterOptions>;
|
|
213
|
+
|
|
214
|
+
export { generateRouter };
|
|
215
|
+
export type { GenerateRouterOptions, NameStrategy, OutputFormat, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig };
|