@gylautorun/dev-proxy-cookie 1.0.0 → 1.0.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.md +214 -2
- package/dist/index.d.mts +347 -31
- package/dist/index.d.ts +347 -31
- package/dist/index.js +411 -145
- package/dist/index.min.js +4 -4
- package/dist/index.min.mjs +4 -4
- package/dist/index.mjs +407 -140
- package/package.json +1 -1
- package/src/index.ts +13 -0
- package/src/proxy/apply-dev-cookie-header.ts +35 -5
- package/src/proxy/core.ts +214 -15
- package/src/proxy/index.ts +8 -3
- package/src/proxy/vite-middleware-plugin.ts +158 -0
- package/src/proxy/vue-proxy-config.ts +112 -9
- package/src/utils/cookie-reader.ts +74 -3
- package/src/utils/cookie-watcher.ts +50 -1
- package/src/utils/env-detector.ts +162 -0
- package/src/utils/index.ts +9 -1
- package/src/proxy/vite-adapter.ts +0 -77
- package/src/proxy/vite-cookie-plugin.ts +0 -60
- package/src/proxy/vite-plugin.ts +0 -55
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import * as net from 'net';
|
|
2
2
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
-
import { ViteDevServer
|
|
3
|
+
import { ViteDevServer } from 'vite';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* 错误回调函数类型
|
|
7
|
+
* @param err - 错误对象
|
|
8
|
+
* @param req - 请求对象
|
|
9
|
+
* @param res - 响应对象或 Socket
|
|
10
|
+
*/
|
|
5
11
|
type ErrorCallback = (err: Error, req: IncomingMessage, res: ServerResponse | net.Socket) => void;
|
|
6
12
|
interface ProxyHooks {
|
|
7
13
|
onProxyReq?: (proxyReq: any, req: IncomingMessage, res: ServerResponse) => void;
|
|
@@ -16,6 +22,12 @@ interface AutoProxyCookieOptions {
|
|
|
16
22
|
autoRestart?: boolean;
|
|
17
23
|
restartMarkerFile?: string;
|
|
18
24
|
proxyMap?: Record<string, string>;
|
|
25
|
+
/**
|
|
26
|
+
* 需要代理的路径前缀列表(默认代理到 target)
|
|
27
|
+
* 例如: ['/api', '/digital-platform']
|
|
28
|
+
* 如果请求路径匹配这些前缀之一,将被代理到 target
|
|
29
|
+
*/
|
|
30
|
+
proxyPaths?: string[];
|
|
19
31
|
ignorePaths?: string[];
|
|
20
32
|
ws?: boolean;
|
|
21
33
|
changeOrigin?: boolean;
|
|
@@ -34,128 +46,432 @@ interface AutoProxyCookieOptions {
|
|
|
34
46
|
[header: string]: string;
|
|
35
47
|
};
|
|
36
48
|
hooks?: ProxyHooks;
|
|
49
|
+
/**
|
|
50
|
+
* 是否启用文件监听
|
|
51
|
+
* - 'auto': 自动(如果 isDev 为 true,则启用监听)
|
|
52
|
+
* - true: 强制启用监听
|
|
53
|
+
* - false: 禁用监听
|
|
54
|
+
*
|
|
55
|
+
* 默认值: 'auto'
|
|
56
|
+
*/
|
|
57
|
+
watch?: 'auto' | boolean;
|
|
58
|
+
/**
|
|
59
|
+
* 是否为开发环境(优先级最高)
|
|
60
|
+
* 设置此参数后,将直接决定是否启用文件监听:
|
|
61
|
+
* - true: 启用监听(开发模式)
|
|
62
|
+
* - false: 禁用监听(生产模式)
|
|
63
|
+
*
|
|
64
|
+
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
65
|
+
*/
|
|
66
|
+
isDev?: boolean;
|
|
37
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* 自动代理 Cookie 类
|
|
70
|
+
*
|
|
71
|
+
* 提供完整的开发环境代理解决方案,支持 HTTP 和 WebSocket 代理,
|
|
72
|
+
* 自动从文件读取 Cookie 并注入到代理请求中。
|
|
73
|
+
*/
|
|
38
74
|
declare class AutoProxyCookie {
|
|
75
|
+
/** 合并后的配置选项 */
|
|
39
76
|
private options;
|
|
77
|
+
/** 当前 Cookie 值 */
|
|
40
78
|
private currentCookie;
|
|
79
|
+
/** Vite 开发服务器实例 */
|
|
41
80
|
private server;
|
|
81
|
+
/** HTTP 代理服务器实例 */
|
|
42
82
|
private proxyServer;
|
|
83
|
+
/** Cookie 文件监听器 */
|
|
43
84
|
private watcher;
|
|
85
|
+
/** Cookie 文件读取器 */
|
|
44
86
|
private cookieReader;
|
|
87
|
+
/**
|
|
88
|
+
* 构造函数
|
|
89
|
+
* @param options - 配置选项
|
|
90
|
+
*/
|
|
45
91
|
constructor(options: AutoProxyCookieOptions);
|
|
92
|
+
/**
|
|
93
|
+
* Cookie 变化处理函数
|
|
94
|
+
* @param newCookie - 新的 Cookie 值
|
|
95
|
+
*/
|
|
46
96
|
private handleCookieChange;
|
|
97
|
+
/**
|
|
98
|
+
* 根据请求路径获取代理目标 URL
|
|
99
|
+
* @param req - HTTP 请求对象
|
|
100
|
+
* @returns 代理目标 URL
|
|
101
|
+
*/
|
|
47
102
|
private getProxyUrl;
|
|
103
|
+
/**
|
|
104
|
+
* 判断路径是否应该被忽略(不代理)
|
|
105
|
+
* @param pathname - 请求路径
|
|
106
|
+
* @returns 是否忽略
|
|
107
|
+
*/
|
|
48
108
|
private isIgnoredPath;
|
|
109
|
+
/**
|
|
110
|
+
* 日志输出函数
|
|
111
|
+
* @param level - 日志级别
|
|
112
|
+
* @param args - 日志参数
|
|
113
|
+
*/
|
|
49
114
|
private log;
|
|
115
|
+
/**
|
|
116
|
+
* 创建代理服务器配置选项
|
|
117
|
+
* @param target - 代理目标地址
|
|
118
|
+
* @returns 代理服务器配置
|
|
119
|
+
*/
|
|
50
120
|
private createProxyOptions;
|
|
121
|
+
/**
|
|
122
|
+
* 代理请求处理函数
|
|
123
|
+
* @param proxyReq - 代理请求对象
|
|
124
|
+
* @param req - 原始请求对象
|
|
125
|
+
* @param res - 响应对象
|
|
126
|
+
* @param _options - 服务器选项
|
|
127
|
+
*/
|
|
51
128
|
private handleOnProxyReq;
|
|
129
|
+
/**
|
|
130
|
+
* 代理响应处理函数
|
|
131
|
+
* @param proxyRes - 代理响应对象
|
|
132
|
+
* @param req - 原始请求对象
|
|
133
|
+
* @param res - 响应对象
|
|
134
|
+
*/
|
|
52
135
|
private handleOnProxyRes;
|
|
136
|
+
/**
|
|
137
|
+
* HTTP 代理错误处理函数
|
|
138
|
+
* @param err - 错误对象
|
|
139
|
+
* @param req - 请求对象
|
|
140
|
+
* @param res - 响应对象或 Socket
|
|
141
|
+
*/
|
|
53
142
|
private handleOnError;
|
|
143
|
+
/**
|
|
144
|
+
* WebSocket 代理错误处理函数
|
|
145
|
+
* @param err - 错误对象
|
|
146
|
+
* @param req - 请求对象
|
|
147
|
+
* @param socket - WebSocket 连接的 Socket
|
|
148
|
+
*/
|
|
54
149
|
private handleOnWsError;
|
|
150
|
+
/**
|
|
151
|
+
* 初始化代理中间件
|
|
152
|
+
* @param server - Vite 开发服务器实例
|
|
153
|
+
*/
|
|
55
154
|
setup(server: ViteDevServer): Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* 启动 Cookie 文件监听
|
|
157
|
+
*/
|
|
56
158
|
private startFileWatch;
|
|
159
|
+
/**
|
|
160
|
+
* 停止代理服务
|
|
161
|
+
*/
|
|
57
162
|
stop(): void;
|
|
163
|
+
/**
|
|
164
|
+
* 获取当前 Cookie 值
|
|
165
|
+
* @returns 当前 Cookie 字符串
|
|
166
|
+
*/
|
|
58
167
|
getCurrentCookie(): string;
|
|
59
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* 创建 AutoProxyCookie 实例
|
|
171
|
+
* @param options - 配置选项
|
|
172
|
+
* @returns AutoProxyCookie 实例
|
|
173
|
+
*/
|
|
60
174
|
declare function createAutoProxyCookie(options: AutoProxyCookieOptions): AutoProxyCookie;
|
|
61
175
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
interface ViteDevProxyCookieOptions {
|
|
176
|
+
/**
|
|
177
|
+
* Vite 中间件代理 Cookie 插件配置选项
|
|
178
|
+
*/
|
|
179
|
+
interface ViteMiddlewareProxyOptions {
|
|
180
|
+
/** Cookie 文件路径 */
|
|
68
181
|
cookieFile: string;
|
|
182
|
+
/** 默认代理目标地址 */
|
|
183
|
+
target: string;
|
|
184
|
+
/** 是否启用调试日志 */
|
|
69
185
|
debug?: boolean;
|
|
70
|
-
|
|
186
|
+
/**
|
|
187
|
+
* 代理路径映射表
|
|
188
|
+
* 键:路径前缀,值:代理目标地址
|
|
189
|
+
*/
|
|
190
|
+
proxyMap?: Record<string, string>;
|
|
191
|
+
/**
|
|
192
|
+
* 需要代理的路径前缀列表(使用默认 target)
|
|
193
|
+
*/
|
|
194
|
+
proxyPaths?: string[];
|
|
195
|
+
/**
|
|
196
|
+
* 需要忽略的路径前缀列表(不代理)
|
|
197
|
+
*/
|
|
198
|
+
ignorePaths?: string[];
|
|
71
199
|
}
|
|
72
|
-
|
|
200
|
+
/**
|
|
201
|
+
* 创建 Vite 中间件代理 Cookie 插件
|
|
202
|
+
*
|
|
203
|
+
* @param options - 插件配置选项
|
|
204
|
+
* @returns Vite 插件对象
|
|
205
|
+
*/
|
|
206
|
+
declare function viteMiddlewareProxy(options: ViteMiddlewareProxyOptions): any;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Vue CLI 代理配置模块
|
|
210
|
+
*
|
|
211
|
+
* 提供 Vue CLI 开发服务器的代理配置功能,支持从文件读取 Cookie 并注入代理请求。
|
|
212
|
+
* 核心函数包括 createFileCookieGetter 和 createVueProxyConfig。
|
|
213
|
+
*
|
|
214
|
+
* @module vue-proxy-config
|
|
215
|
+
*/
|
|
73
216
|
|
|
74
217
|
/** Options for {@link createFileCookieGetter}. */
|
|
75
218
|
interface CreateFileCookieGetterOptions {
|
|
76
219
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
220
|
+
* 是否监听文件变化
|
|
221
|
+
* - true: 始终监听
|
|
222
|
+
* - false: 从不监听
|
|
223
|
+
* - 'auto': 根据环境自动判断(默认)
|
|
224
|
+
*
|
|
225
|
+
* Cookie 值每次代理请求时都会从磁盘读取,因此即使 watch 为 false,
|
|
226
|
+
* 修改 cookie 文件后也不需要重启开发服务器。
|
|
227
|
+
* @default 'auto'
|
|
80
228
|
*/
|
|
81
|
-
watch?: boolean;
|
|
229
|
+
watch?: boolean | 'auto';
|
|
82
230
|
/** Log when the cookie file changes (only if `watch` is true). @default false */
|
|
83
231
|
debug?: boolean;
|
|
232
|
+
/**
|
|
233
|
+
* 自定义生产环境变量名称列表,用于判断是否禁用监听
|
|
234
|
+
* 例如: ['MY_APP_ENV', 'BUILD_TYPE']
|
|
235
|
+
*/
|
|
236
|
+
productionEnvs?: string[];
|
|
237
|
+
/**
|
|
238
|
+
* 是否为开发环境(优先级最高)
|
|
239
|
+
* 设置此参数后,将直接决定是否启用文件监听:
|
|
240
|
+
* - true: 启用监听(开发模式)
|
|
241
|
+
* - false: 禁用监听(生产模式)
|
|
242
|
+
*
|
|
243
|
+
* 使用示例: isDev: process.env.NODE_ENV === 'development'
|
|
244
|
+
*/
|
|
245
|
+
isDev?: boolean;
|
|
84
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Vue 代理配置选项
|
|
249
|
+
*/
|
|
85
250
|
interface VueProxyConfigOptions {
|
|
251
|
+
/** Cookie 获取函数 */
|
|
86
252
|
getCookie?: () => string;
|
|
253
|
+
/** 是否输出调试日志 */
|
|
87
254
|
debug?: boolean;
|
|
255
|
+
/** 自定义请求头 */
|
|
88
256
|
headers?: Record<string, string>;
|
|
257
|
+
/** 是否启用 WebSocket 代理 */
|
|
89
258
|
ws?: boolean;
|
|
259
|
+
/** 是否修改请求头中的 Origin */
|
|
90
260
|
changeOrigin?: boolean;
|
|
261
|
+
/** 是否验证 SSL 证书 */
|
|
91
262
|
secure?: boolean;
|
|
263
|
+
/** 错误回调函数 */
|
|
92
264
|
onError?: (err: Error) => void;
|
|
93
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Vue CLI 代理配置接口
|
|
268
|
+
*
|
|
269
|
+
* 符合 Vue CLI 代理配置格式的对象结构
|
|
270
|
+
*/
|
|
94
271
|
interface ProxyConfig {
|
|
272
|
+
/** 是否启用 WebSocket 代理 */
|
|
95
273
|
ws: boolean;
|
|
274
|
+
/** 代理目标地址 */
|
|
96
275
|
target: string;
|
|
276
|
+
/** 是否修改请求头中的 Origin */
|
|
97
277
|
changeOrigin: boolean;
|
|
278
|
+
/** 是否验证 SSL 证书 */
|
|
98
279
|
secure: boolean;
|
|
280
|
+
/** 代理请求前的回调函数 */
|
|
99
281
|
onProxyReq: (proxyReq: any, req: IncomingMessage) => void;
|
|
282
|
+
/** 代理响应后的回调函数(可选) */
|
|
100
283
|
onProxyRes?: (proxyRes: any, req: IncomingMessage) => void;
|
|
284
|
+
/** 错误处理回调函数 */
|
|
101
285
|
onError: (err: Error) => void;
|
|
286
|
+
/** 自定义请求头 */
|
|
102
287
|
headers?: Record<string, string>;
|
|
103
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* 创建 Vue CLI 代理配置
|
|
291
|
+
*
|
|
292
|
+
* @param target - 代理目标地址
|
|
293
|
+
* @param options - 配置选项
|
|
294
|
+
* @returns Vue CLI 代理配置对象
|
|
295
|
+
*/
|
|
104
296
|
declare function createVueProxyConfig(target: string, options?: VueProxyConfigOptions): ProxyConfig;
|
|
297
|
+
/**
|
|
298
|
+
* 创建文件 Cookie 获取器
|
|
299
|
+
*
|
|
300
|
+
* 从指定文件读取 Cookie 值,支持文件监听功能。
|
|
301
|
+
*
|
|
302
|
+
* @param cookieFile - Cookie 文件路径
|
|
303
|
+
* @param options - 配置选项
|
|
304
|
+
* @returns Cookie 获取函数
|
|
305
|
+
*/
|
|
105
306
|
declare function createFileCookieGetter(cookieFile: string, options?: CreateFileCookieGetterOptions): () => string;
|
|
307
|
+
/**
|
|
308
|
+
* 自动代理配置选项
|
|
309
|
+
*/
|
|
106
310
|
interface AutoProxyConfigOptions extends VueProxyConfigOptions {
|
|
311
|
+
/** 代理目标地址 */
|
|
107
312
|
target: string;
|
|
313
|
+
/** 忽略的路径列表(不代理这些路径) */
|
|
108
314
|
ignorePaths?: string[];
|
|
315
|
+
/** 包含的路径列表(只代理这些路径) */
|
|
109
316
|
includePaths?: string[];
|
|
317
|
+
/** 额外的代理配置 */
|
|
110
318
|
additionalProxies?: Record<string, string>;
|
|
111
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* 创建自动代理配置
|
|
322
|
+
*
|
|
323
|
+
* 根据配置自动生成 Vue CLI 代理配置对象,支持忽略路径和包含路径两种模式。
|
|
324
|
+
*
|
|
325
|
+
* @param options - 配置选项
|
|
326
|
+
* @returns Vue CLI 代理配置对象映射
|
|
327
|
+
*/
|
|
112
328
|
declare function createAutoProxyConfig(options: AutoProxyConfigOptions): Record<string, ProxyConfig>;
|
|
113
329
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
debug?: boolean;
|
|
118
|
-
autoRestart?: boolean;
|
|
119
|
-
restartMarkerFile?: string;
|
|
120
|
-
proxyMap?: Record<string, string>;
|
|
121
|
-
ignorePaths?: string[];
|
|
122
|
-
includePaths?: string[];
|
|
123
|
-
onCookieChange?: (cookie: string) => void;
|
|
124
|
-
mode?: 'auto' | 'proxy' | 'cookie';
|
|
125
|
-
}
|
|
126
|
-
declare function createDevProxyCookie(options: UnifiedProxyCookieOptions): Plugin;
|
|
127
|
-
declare function getViteVersion(): string | null;
|
|
128
|
-
declare function getViteMajorVersion(): number;
|
|
129
|
-
|
|
330
|
+
/**
|
|
331
|
+
* Cookie 读取器配置选项
|
|
332
|
+
*/
|
|
130
333
|
interface CookieReaderOptions {
|
|
131
334
|
cookieFile: string;
|
|
132
335
|
encoding?: BufferEncoding;
|
|
133
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Cookie 文件读取器类
|
|
339
|
+
*
|
|
340
|
+
* 提供从文件读取 Cookie 的功能,支持注释过滤和自动文件创建。
|
|
341
|
+
*/
|
|
134
342
|
declare class CookieReader {
|
|
343
|
+
/** 配置选项 */
|
|
135
344
|
protected options: CookieReaderOptions;
|
|
136
|
-
|
|
345
|
+
/** 是否启用调试模式 */
|
|
346
|
+
protected debug: boolean;
|
|
347
|
+
/**
|
|
348
|
+
* 构造函数
|
|
349
|
+
* @param options - 配置选项
|
|
350
|
+
* @param debug - 是否启用调试模式
|
|
351
|
+
*/
|
|
352
|
+
constructor(options: CookieReaderOptions, debug?: boolean);
|
|
353
|
+
/**
|
|
354
|
+
* 读取 Cookie 文件内容
|
|
355
|
+
*
|
|
356
|
+
* 支持过滤注释行(以 # 开头)和空行,将有效行用分号连接。
|
|
357
|
+
*
|
|
358
|
+
* @returns Cookie 字符串
|
|
359
|
+
*/
|
|
137
360
|
readCookie(): string;
|
|
361
|
+
/**
|
|
362
|
+
* 确保 Cookie 文件存在
|
|
363
|
+
*
|
|
364
|
+
* 如果文件不存在,会自动创建空文件。
|
|
365
|
+
* 如果父目录不存在,会自动创建目录。
|
|
366
|
+
*/
|
|
138
367
|
ensureCookieFile(): void;
|
|
139
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* 创建 Cookie 获取器函数
|
|
371
|
+
*
|
|
372
|
+
* 返回一个函数,每次调用时从文件读取最新的 Cookie 值。
|
|
373
|
+
*
|
|
374
|
+
* @param cookieFile - Cookie 文件路径
|
|
375
|
+
* @returns Cookie 获取函数
|
|
376
|
+
*/
|
|
140
377
|
declare function createCookieGetter(cookieFile: string): () => string;
|
|
141
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Cookie 监听器配置选项
|
|
381
|
+
*/
|
|
142
382
|
interface CookieWatcherOptions {
|
|
143
383
|
cookieFile: string;
|
|
144
384
|
onCookieChange: (cookie: string) => void;
|
|
145
385
|
onError?: (error: Error) => void;
|
|
146
386
|
autoCreateFile?: boolean;
|
|
147
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Cookie 文件监听器类
|
|
390
|
+
*
|
|
391
|
+
* 使用 chokidar 监听 Cookie 文件变化,当文件内容改变时触发回调。
|
|
392
|
+
* 支持自动创建文件和稳定性阈值配置。
|
|
393
|
+
*/
|
|
148
394
|
declare class CookieWatcher {
|
|
395
|
+
/** 文件监听器实例 */
|
|
149
396
|
private watcher;
|
|
397
|
+
/** 配置选项 */
|
|
150
398
|
private options;
|
|
399
|
+
/** Cookie 读取器 */
|
|
151
400
|
private cookieReader;
|
|
401
|
+
/** 上次读取的 Cookie 内容 */
|
|
152
402
|
private lastContent;
|
|
403
|
+
/**
|
|
404
|
+
* 构造函数
|
|
405
|
+
* @param options - 配置选项
|
|
406
|
+
*/
|
|
153
407
|
constructor(options: CookieWatcherOptions);
|
|
408
|
+
/**
|
|
409
|
+
* 文件变化处理函数
|
|
410
|
+
*
|
|
411
|
+
* 读取新的 Cookie 内容,如果与上次不同则触发回调。
|
|
412
|
+
*/
|
|
154
413
|
private handleChange;
|
|
414
|
+
/**
|
|
415
|
+
* 启动文件监听
|
|
416
|
+
*/
|
|
155
417
|
start(): void;
|
|
418
|
+
/**
|
|
419
|
+
* 停止文件监听
|
|
420
|
+
*/
|
|
156
421
|
stop(): void;
|
|
422
|
+
/**
|
|
423
|
+
* 获取当前 Cookie 值
|
|
424
|
+
* @returns 当前 Cookie 字符串
|
|
425
|
+
*/
|
|
157
426
|
getCurrentCookie(): string;
|
|
158
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* 创建并启动 Cookie 文件监听器
|
|
430
|
+
*
|
|
431
|
+
* @param cookieFile - Cookie 文件路径
|
|
432
|
+
* @param onCookieChange - Cookie 变化回调函数
|
|
433
|
+
* @param onError - 错误回调函数(可选)
|
|
434
|
+
* @returns CookieWatcher 实例
|
|
435
|
+
*/
|
|
159
436
|
declare function watchCookieFile(cookieFile: string, onCookieChange: (cookie: string) => void, onError?: (error: Error) => void): CookieWatcher;
|
|
160
437
|
|
|
161
|
-
|
|
438
|
+
/**
|
|
439
|
+
* 环境检测工具模块
|
|
440
|
+
*
|
|
441
|
+
* 提供智能环境检测功能,用于判断当前是否为生产构建环境,
|
|
442
|
+
* 从而决定是否启用文件监听等开发环境特性。
|
|
443
|
+
*
|
|
444
|
+
* @module env-detector
|
|
445
|
+
*/
|
|
446
|
+
/**
|
|
447
|
+
* 判断环境变量值是否表示生产环境
|
|
448
|
+
*
|
|
449
|
+
* @param value - 环境变量值
|
|
450
|
+
* @returns 是否为生产环境值
|
|
451
|
+
*/
|
|
452
|
+
declare function isProductionValue(value: string): boolean;
|
|
453
|
+
/**
|
|
454
|
+
* 智能检测当前是否为生产构建环境
|
|
455
|
+
* 通过多种方式综合判断,避免依赖单一环境变量
|
|
456
|
+
*
|
|
457
|
+
* @param customEnvs 用户自定义的环境变量名称列表
|
|
458
|
+
* @param debug 是否输出调试日志
|
|
459
|
+
* @param loggerPrefix 日志前缀,用于区分不同模块
|
|
460
|
+
* @returns 是否为生产环境
|
|
461
|
+
*/
|
|
462
|
+
declare function detectProductionEnvironment(customEnvs?: string[], debug?: boolean, loggerPrefix?: string): boolean;
|
|
463
|
+
/**
|
|
464
|
+
* 判断是否应该启用文件监听
|
|
465
|
+
*
|
|
466
|
+
* 注意:此函数仅在 isDev 参数未设置时调用,用于智能判断环境
|
|
467
|
+
* 如果用户已通过 isDev 参数明确指定环境,则不会调用此函数
|
|
468
|
+
*
|
|
469
|
+
* @param watch 用户设置的 watch 选项
|
|
470
|
+
* @param customEnvs 用户自定义的环境变量列表
|
|
471
|
+
* @param debug 是否输出调试日志
|
|
472
|
+
* @param loggerPrefix 日志前缀
|
|
473
|
+
* @returns 是否应该启用监听
|
|
474
|
+
*/
|
|
475
|
+
declare function shouldEnableWatch(watch: boolean | 'auto', customEnvs?: string[], debug?: boolean, loggerPrefix?: string): boolean;
|
|
476
|
+
|
|
477
|
+
export { type AutoProxyConfigOptions, AutoProxyCookie, type AutoProxyCookieOptions, CookieReader, type CookieReaderOptions, CookieWatcher, type CookieWatcherOptions, type CreateFileCookieGetterOptions, type ErrorCallback, type ProxyConfig, type ProxyHooks, type ViteMiddlewareProxyOptions, type VueProxyConfigOptions, createAutoProxyConfig, createAutoProxyCookie, createCookieGetter, createFileCookieGetter, createVueProxyConfig, detectProductionEnvironment, isProductionValue, shouldEnableWatch, viteMiddlewareProxy, watchCookieFile };
|