@xysfe/vite-plugin-dev-proxy 1.0.2 → 1.0.4

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/dist/index.d.cts CHANGED
@@ -1,17 +1,191 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
+ /**
4
+ * 代理插件配置选项
5
+ * @interface ProxyOptions
6
+ */
3
7
  interface ProxyOptions {
8
+ /** 是否使用HTTPS协议,默认true */
4
9
  https?: boolean;
10
+ /** 代理目标主机地址(必填),如:'example.com' */
5
11
  appHost?: string;
6
- isLib?: boolean;
12
+ /** 本地HTML文件路径,默认'' */
7
13
  localIndexHtml?: string;
14
+ /** 静态资源路径前缀,默认为空字符串 */
8
15
  staticPrefix?: string;
9
- bypassPrefixes?: string[];
16
+ /** 远程资源路径前缀规则,支持字符串、数组、函数、正则,默认['/static/component'] */
17
+ remotePrefixes?: string | string[] | Function | RegExp;
18
+ /** 清除脚本/CSS的前缀规则,支持字符串、数组、函数、正则 */
10
19
  clearScriptCssPrefixes?: string | string[] | Function | RegExp;
20
+ /** 开发代理占位符,用于替换为入口脚本 */
11
21
  developmentAgentOccupancy?: string;
12
- entry?: string;
22
+ /** 入口文件路径,支持单个或多个入口,默认'/src/main.js' */
23
+ entry?: string | string[];
24
+ /** 是否开启调试模式,开启后会输出详细日志,默认false */
13
25
  debug?: boolean;
14
26
  }
27
+ /**
28
+ * HTTP请求消息对象
29
+ * @interface IncomingMessage
30
+ */
31
+ interface IncomingMessage {
32
+ /** 请求URL */
33
+ url?: string;
34
+ /** 请求头 */
35
+ headers: {
36
+ [key: string]: string | string[] | undefined;
37
+ };
38
+ /** 请求方法 */
39
+ method?: string;
40
+ /** 主机地址 */
41
+ host?: string;
42
+ /** Accept头 */
43
+ accept?: string;
44
+ }
45
+ /**
46
+ * 代理响应对象
47
+ * @interface ProxyResponse
48
+ */
49
+ interface ProxyResponse {
50
+ /** HTTP状态码 */
51
+ statusCode: number;
52
+ /** 响应头 */
53
+ headers: {
54
+ [key: string]: string | string[] | undefined;
55
+ };
56
+ /** 监听事件 */
57
+ on: (event: string, callback: (chunk?: Buffer) => void) => void;
58
+ /** 管道传输 */
59
+ pipe: (destination: any) => void;
60
+ }
61
+ /**
62
+ * HTTP响应对象
63
+ * @interface ServerResponse
64
+ */
65
+ interface ServerResponse {
66
+ /** 写入响应头 */
67
+ writeHead: (statusCode: number, headers?: {
68
+ [key: string]: string | string[] | undefined;
69
+ }) => void;
70
+ /** 结束响应 */
71
+ end: (data?: string) => void;
72
+ /** 响应头是否已发送 */
73
+ headersSent?: boolean;
74
+ }
75
+
76
+ /**
77
+ * Vite开发代理插件
78
+ *
79
+ * 用于在开发环境下代理远程服务器,同时支持本地模块热更新。
80
+ * 主要特性:
81
+ * - 自动代理远程服务器的HTML、API等请求
82
+ * - 自动注入本地入口脚本到远程HTML
83
+ * - 支持清除远程HTML中的脚本和样式标签
84
+ * - 处理Cookie、重定向等,确保本地开发体验
85
+ * - 支持多入口配置
86
+ * - 支持库模式,使用本地HTML文件
87
+ *
88
+ * @param {ProxyOptions} options - 插件配置选项
89
+ * @returns {Plugin} Vite插件对象
90
+ *
91
+ * @example
92
+ * // vite.config.js
93
+ * import viteDevProxy from 'vite-plugin-dev-proxy';
94
+ *
95
+ * export default {
96
+ * plugins: [
97
+ * viteDevProxy({
98
+ * appHost: 'example.com',
99
+ * https: true,
100
+ * entry: '/src/main.js',
101
+ * staticPrefix: '',
102
+ * remotePrefixes: ['/static'],
103
+ * clearScriptCssPrefixes: '/static',
104
+ * debug: true
105
+ * })
106
+ * ]
107
+ * }
108
+ */
15
109
  declare function viteDevProxy(options?: ProxyOptions): Plugin;
16
110
 
17
- export { viteDevProxy as default };
111
+ /**
112
+ * 代理配置对象
113
+ * @interface ProxyConfig
114
+ */
115
+ interface ProxyConfig {
116
+ /** 代理目标地址 */
117
+ target: string;
118
+ /** 是否改变origin头 */
119
+ changeOrigin: boolean;
120
+ /** 是否验证SSL证书 */
121
+ secure: boolean;
122
+ /** Cookie域名重写配置 */
123
+ cookieDomainRewrite: {
124
+ [key: string]: string;
125
+ };
126
+ /** 是否自行处理响应 */
127
+ selfHandleResponse: boolean;
128
+ ws?: boolean;
129
+ /** 代理请求钩子 */
130
+ onProxyReq?: (proxyReq: any, req: IncomingMessage, res: ServerResponse) => void;
131
+ /** 代理错误钩子 */
132
+ onError?: (err: Error, req: IncomingMessage, res: ServerResponse) => void;
133
+ /** 代理响应钩子 */
134
+ onProxyRes?: (proxyRes: ProxyResponse, req: IncomingMessage, res: ServerResponse) => void;
135
+ /** 请求绕过函数,返回url则使用本地资源 */
136
+ bypass?: (req: IncomingMessage) => string | null | undefined;
137
+ }
138
+ /**
139
+ * Vue CLI配置对象
140
+ * @interface VueCliConfig
141
+ */
142
+ interface VueCliConfig {
143
+ devServer?: {
144
+ proxy?: Record<string, ProxyConfig>;
145
+ };
146
+ }
147
+ /**
148
+ * 创建Vue CLI开发服务器代理配置
149
+ *
150
+ * @param {ProxyOptions} options - 代理配置选项
151
+ * @returns {Record<string, ProxyConfig>} 返回代理配置对象
152
+ * @throws {Error} 当 appHost 未提供或 remotePrefixes 不是数组时抛出错误
153
+ */
154
+ declare function createVueCliProxyConfig(options: ProxyOptions): Record<string, ProxyConfig>;
155
+ /**
156
+ * Vue CLI开发代理插件
157
+ *
158
+ * 用于在开发环境下代理远程服务器,同时支持本地模块热更新。
159
+ * 主要特性:
160
+ * - 自动代理远程服务器的HTML、API等请求
161
+ * - 自动注入本地入口脚本到远程HTML
162
+ * - 支持清除远程HTML中的脚本和样式标签
163
+ * - 处理Cookie、重定向等,确保本地开发体验
164
+ * - 支持多入口配置
165
+ * - 支持库模式,使用本地HTML文件
166
+ *
167
+ * @param {ProxyOptions} options - 插件配置选项
168
+ * @returns {VueCliConfig} Vue CLI配置对象
169
+ *
170
+ * @example
171
+ * // vue.config.js
172
+ * const vueCliDevProxy = require('vite-plugin-dev-proxy/vue-cli');
173
+ *
174
+ * module.exports = vueCliDevProxy({
175
+ * appHost: 'example.com',
176
+ * https: true,
177
+ * entry: '/src/main.js',
178
+ * staticPrefix: '',
179
+ * remotePrefixes: ['/static'],
180
+ * clearScriptCssPrefixes: '/static',
181
+ * debug: true
182
+ * });
183
+ */
184
+ declare function vueCliDevProxy(options?: ProxyOptions): VueCliConfig;
185
+
186
+ declare const _default: {
187
+ VitePluginDevProxy: typeof viteDevProxy;
188
+ VueCliPluginDevProxy: typeof vueCliDevProxy;
189
+ };
190
+
191
+ export { viteDevProxy as VitePluginDevProxy, vueCliDevProxy as VueCliPluginDevProxy, createVueCliProxyConfig, _default as default };
package/dist/index.d.mts CHANGED
@@ -1,17 +1,191 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
+ /**
4
+ * 代理插件配置选项
5
+ * @interface ProxyOptions
6
+ */
3
7
  interface ProxyOptions {
8
+ /** 是否使用HTTPS协议,默认true */
4
9
  https?: boolean;
10
+ /** 代理目标主机地址(必填),如:'example.com' */
5
11
  appHost?: string;
6
- isLib?: boolean;
12
+ /** 本地HTML文件路径,默认'' */
7
13
  localIndexHtml?: string;
14
+ /** 静态资源路径前缀,默认为空字符串 */
8
15
  staticPrefix?: string;
9
- bypassPrefixes?: string[];
16
+ /** 远程资源路径前缀规则,支持字符串、数组、函数、正则,默认['/static/component'] */
17
+ remotePrefixes?: string | string[] | Function | RegExp;
18
+ /** 清除脚本/CSS的前缀规则,支持字符串、数组、函数、正则 */
10
19
  clearScriptCssPrefixes?: string | string[] | Function | RegExp;
20
+ /** 开发代理占位符,用于替换为入口脚本 */
11
21
  developmentAgentOccupancy?: string;
12
- entry?: string;
22
+ /** 入口文件路径,支持单个或多个入口,默认'/src/main.js' */
23
+ entry?: string | string[];
24
+ /** 是否开启调试模式,开启后会输出详细日志,默认false */
13
25
  debug?: boolean;
14
26
  }
27
+ /**
28
+ * HTTP请求消息对象
29
+ * @interface IncomingMessage
30
+ */
31
+ interface IncomingMessage {
32
+ /** 请求URL */
33
+ url?: string;
34
+ /** 请求头 */
35
+ headers: {
36
+ [key: string]: string | string[] | undefined;
37
+ };
38
+ /** 请求方法 */
39
+ method?: string;
40
+ /** 主机地址 */
41
+ host?: string;
42
+ /** Accept头 */
43
+ accept?: string;
44
+ }
45
+ /**
46
+ * 代理响应对象
47
+ * @interface ProxyResponse
48
+ */
49
+ interface ProxyResponse {
50
+ /** HTTP状态码 */
51
+ statusCode: number;
52
+ /** 响应头 */
53
+ headers: {
54
+ [key: string]: string | string[] | undefined;
55
+ };
56
+ /** 监听事件 */
57
+ on: (event: string, callback: (chunk?: Buffer) => void) => void;
58
+ /** 管道传输 */
59
+ pipe: (destination: any) => void;
60
+ }
61
+ /**
62
+ * HTTP响应对象
63
+ * @interface ServerResponse
64
+ */
65
+ interface ServerResponse {
66
+ /** 写入响应头 */
67
+ writeHead: (statusCode: number, headers?: {
68
+ [key: string]: string | string[] | undefined;
69
+ }) => void;
70
+ /** 结束响应 */
71
+ end: (data?: string) => void;
72
+ /** 响应头是否已发送 */
73
+ headersSent?: boolean;
74
+ }
75
+
76
+ /**
77
+ * Vite开发代理插件
78
+ *
79
+ * 用于在开发环境下代理远程服务器,同时支持本地模块热更新。
80
+ * 主要特性:
81
+ * - 自动代理远程服务器的HTML、API等请求
82
+ * - 自动注入本地入口脚本到远程HTML
83
+ * - 支持清除远程HTML中的脚本和样式标签
84
+ * - 处理Cookie、重定向等,确保本地开发体验
85
+ * - 支持多入口配置
86
+ * - 支持库模式,使用本地HTML文件
87
+ *
88
+ * @param {ProxyOptions} options - 插件配置选项
89
+ * @returns {Plugin} Vite插件对象
90
+ *
91
+ * @example
92
+ * // vite.config.js
93
+ * import viteDevProxy from 'vite-plugin-dev-proxy';
94
+ *
95
+ * export default {
96
+ * plugins: [
97
+ * viteDevProxy({
98
+ * appHost: 'example.com',
99
+ * https: true,
100
+ * entry: '/src/main.js',
101
+ * staticPrefix: '',
102
+ * remotePrefixes: ['/static'],
103
+ * clearScriptCssPrefixes: '/static',
104
+ * debug: true
105
+ * })
106
+ * ]
107
+ * }
108
+ */
15
109
  declare function viteDevProxy(options?: ProxyOptions): Plugin;
16
110
 
17
- export { viteDevProxy as default };
111
+ /**
112
+ * 代理配置对象
113
+ * @interface ProxyConfig
114
+ */
115
+ interface ProxyConfig {
116
+ /** 代理目标地址 */
117
+ target: string;
118
+ /** 是否改变origin头 */
119
+ changeOrigin: boolean;
120
+ /** 是否验证SSL证书 */
121
+ secure: boolean;
122
+ /** Cookie域名重写配置 */
123
+ cookieDomainRewrite: {
124
+ [key: string]: string;
125
+ };
126
+ /** 是否自行处理响应 */
127
+ selfHandleResponse: boolean;
128
+ ws?: boolean;
129
+ /** 代理请求钩子 */
130
+ onProxyReq?: (proxyReq: any, req: IncomingMessage, res: ServerResponse) => void;
131
+ /** 代理错误钩子 */
132
+ onError?: (err: Error, req: IncomingMessage, res: ServerResponse) => void;
133
+ /** 代理响应钩子 */
134
+ onProxyRes?: (proxyRes: ProxyResponse, req: IncomingMessage, res: ServerResponse) => void;
135
+ /** 请求绕过函数,返回url则使用本地资源 */
136
+ bypass?: (req: IncomingMessage) => string | null | undefined;
137
+ }
138
+ /**
139
+ * Vue CLI配置对象
140
+ * @interface VueCliConfig
141
+ */
142
+ interface VueCliConfig {
143
+ devServer?: {
144
+ proxy?: Record<string, ProxyConfig>;
145
+ };
146
+ }
147
+ /**
148
+ * 创建Vue CLI开发服务器代理配置
149
+ *
150
+ * @param {ProxyOptions} options - 代理配置选项
151
+ * @returns {Record<string, ProxyConfig>} 返回代理配置对象
152
+ * @throws {Error} 当 appHost 未提供或 remotePrefixes 不是数组时抛出错误
153
+ */
154
+ declare function createVueCliProxyConfig(options: ProxyOptions): Record<string, ProxyConfig>;
155
+ /**
156
+ * Vue CLI开发代理插件
157
+ *
158
+ * 用于在开发环境下代理远程服务器,同时支持本地模块热更新。
159
+ * 主要特性:
160
+ * - 自动代理远程服务器的HTML、API等请求
161
+ * - 自动注入本地入口脚本到远程HTML
162
+ * - 支持清除远程HTML中的脚本和样式标签
163
+ * - 处理Cookie、重定向等,确保本地开发体验
164
+ * - 支持多入口配置
165
+ * - 支持库模式,使用本地HTML文件
166
+ *
167
+ * @param {ProxyOptions} options - 插件配置选项
168
+ * @returns {VueCliConfig} Vue CLI配置对象
169
+ *
170
+ * @example
171
+ * // vue.config.js
172
+ * const vueCliDevProxy = require('vite-plugin-dev-proxy/vue-cli');
173
+ *
174
+ * module.exports = vueCliDevProxy({
175
+ * appHost: 'example.com',
176
+ * https: true,
177
+ * entry: '/src/main.js',
178
+ * staticPrefix: '',
179
+ * remotePrefixes: ['/static'],
180
+ * clearScriptCssPrefixes: '/static',
181
+ * debug: true
182
+ * });
183
+ */
184
+ declare function vueCliDevProxy(options?: ProxyOptions): VueCliConfig;
185
+
186
+ declare const _default: {
187
+ VitePluginDevProxy: typeof viteDevProxy;
188
+ VueCliPluginDevProxy: typeof vueCliDevProxy;
189
+ };
190
+
191
+ export { viteDevProxy as VitePluginDevProxy, vueCliDevProxy as VueCliPluginDevProxy, createVueCliProxyConfig, _default as default };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,191 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
+ /**
4
+ * 代理插件配置选项
5
+ * @interface ProxyOptions
6
+ */
3
7
  interface ProxyOptions {
8
+ /** 是否使用HTTPS协议,默认true */
4
9
  https?: boolean;
10
+ /** 代理目标主机地址(必填),如:'example.com' */
5
11
  appHost?: string;
6
- isLib?: boolean;
12
+ /** 本地HTML文件路径,默认'' */
7
13
  localIndexHtml?: string;
14
+ /** 静态资源路径前缀,默认为空字符串 */
8
15
  staticPrefix?: string;
9
- bypassPrefixes?: string[];
16
+ /** 远程资源路径前缀规则,支持字符串、数组、函数、正则,默认['/static/component'] */
17
+ remotePrefixes?: string | string[] | Function | RegExp;
18
+ /** 清除脚本/CSS的前缀规则,支持字符串、数组、函数、正则 */
10
19
  clearScriptCssPrefixes?: string | string[] | Function | RegExp;
20
+ /** 开发代理占位符,用于替换为入口脚本 */
11
21
  developmentAgentOccupancy?: string;
12
- entry?: string;
22
+ /** 入口文件路径,支持单个或多个入口,默认'/src/main.js' */
23
+ entry?: string | string[];
24
+ /** 是否开启调试模式,开启后会输出详细日志,默认false */
13
25
  debug?: boolean;
14
26
  }
27
+ /**
28
+ * HTTP请求消息对象
29
+ * @interface IncomingMessage
30
+ */
31
+ interface IncomingMessage {
32
+ /** 请求URL */
33
+ url?: string;
34
+ /** 请求头 */
35
+ headers: {
36
+ [key: string]: string | string[] | undefined;
37
+ };
38
+ /** 请求方法 */
39
+ method?: string;
40
+ /** 主机地址 */
41
+ host?: string;
42
+ /** Accept头 */
43
+ accept?: string;
44
+ }
45
+ /**
46
+ * 代理响应对象
47
+ * @interface ProxyResponse
48
+ */
49
+ interface ProxyResponse {
50
+ /** HTTP状态码 */
51
+ statusCode: number;
52
+ /** 响应头 */
53
+ headers: {
54
+ [key: string]: string | string[] | undefined;
55
+ };
56
+ /** 监听事件 */
57
+ on: (event: string, callback: (chunk?: Buffer) => void) => void;
58
+ /** 管道传输 */
59
+ pipe: (destination: any) => void;
60
+ }
61
+ /**
62
+ * HTTP响应对象
63
+ * @interface ServerResponse
64
+ */
65
+ interface ServerResponse {
66
+ /** 写入响应头 */
67
+ writeHead: (statusCode: number, headers?: {
68
+ [key: string]: string | string[] | undefined;
69
+ }) => void;
70
+ /** 结束响应 */
71
+ end: (data?: string) => void;
72
+ /** 响应头是否已发送 */
73
+ headersSent?: boolean;
74
+ }
75
+
76
+ /**
77
+ * Vite开发代理插件
78
+ *
79
+ * 用于在开发环境下代理远程服务器,同时支持本地模块热更新。
80
+ * 主要特性:
81
+ * - 自动代理远程服务器的HTML、API等请求
82
+ * - 自动注入本地入口脚本到远程HTML
83
+ * - 支持清除远程HTML中的脚本和样式标签
84
+ * - 处理Cookie、重定向等,确保本地开发体验
85
+ * - 支持多入口配置
86
+ * - 支持库模式,使用本地HTML文件
87
+ *
88
+ * @param {ProxyOptions} options - 插件配置选项
89
+ * @returns {Plugin} Vite插件对象
90
+ *
91
+ * @example
92
+ * // vite.config.js
93
+ * import viteDevProxy from 'vite-plugin-dev-proxy';
94
+ *
95
+ * export default {
96
+ * plugins: [
97
+ * viteDevProxy({
98
+ * appHost: 'example.com',
99
+ * https: true,
100
+ * entry: '/src/main.js',
101
+ * staticPrefix: '',
102
+ * remotePrefixes: ['/static'],
103
+ * clearScriptCssPrefixes: '/static',
104
+ * debug: true
105
+ * })
106
+ * ]
107
+ * }
108
+ */
15
109
  declare function viteDevProxy(options?: ProxyOptions): Plugin;
16
110
 
17
- export { viteDevProxy as default };
111
+ /**
112
+ * 代理配置对象
113
+ * @interface ProxyConfig
114
+ */
115
+ interface ProxyConfig {
116
+ /** 代理目标地址 */
117
+ target: string;
118
+ /** 是否改变origin头 */
119
+ changeOrigin: boolean;
120
+ /** 是否验证SSL证书 */
121
+ secure: boolean;
122
+ /** Cookie域名重写配置 */
123
+ cookieDomainRewrite: {
124
+ [key: string]: string;
125
+ };
126
+ /** 是否自行处理响应 */
127
+ selfHandleResponse: boolean;
128
+ ws?: boolean;
129
+ /** 代理请求钩子 */
130
+ onProxyReq?: (proxyReq: any, req: IncomingMessage, res: ServerResponse) => void;
131
+ /** 代理错误钩子 */
132
+ onError?: (err: Error, req: IncomingMessage, res: ServerResponse) => void;
133
+ /** 代理响应钩子 */
134
+ onProxyRes?: (proxyRes: ProxyResponse, req: IncomingMessage, res: ServerResponse) => void;
135
+ /** 请求绕过函数,返回url则使用本地资源 */
136
+ bypass?: (req: IncomingMessage) => string | null | undefined;
137
+ }
138
+ /**
139
+ * Vue CLI配置对象
140
+ * @interface VueCliConfig
141
+ */
142
+ interface VueCliConfig {
143
+ devServer?: {
144
+ proxy?: Record<string, ProxyConfig>;
145
+ };
146
+ }
147
+ /**
148
+ * 创建Vue CLI开发服务器代理配置
149
+ *
150
+ * @param {ProxyOptions} options - 代理配置选项
151
+ * @returns {Record<string, ProxyConfig>} 返回代理配置对象
152
+ * @throws {Error} 当 appHost 未提供或 remotePrefixes 不是数组时抛出错误
153
+ */
154
+ declare function createVueCliProxyConfig(options: ProxyOptions): Record<string, ProxyConfig>;
155
+ /**
156
+ * Vue CLI开发代理插件
157
+ *
158
+ * 用于在开发环境下代理远程服务器,同时支持本地模块热更新。
159
+ * 主要特性:
160
+ * - 自动代理远程服务器的HTML、API等请求
161
+ * - 自动注入本地入口脚本到远程HTML
162
+ * - 支持清除远程HTML中的脚本和样式标签
163
+ * - 处理Cookie、重定向等,确保本地开发体验
164
+ * - 支持多入口配置
165
+ * - 支持库模式,使用本地HTML文件
166
+ *
167
+ * @param {ProxyOptions} options - 插件配置选项
168
+ * @returns {VueCliConfig} Vue CLI配置对象
169
+ *
170
+ * @example
171
+ * // vue.config.js
172
+ * const vueCliDevProxy = require('vite-plugin-dev-proxy/vue-cli');
173
+ *
174
+ * module.exports = vueCliDevProxy({
175
+ * appHost: 'example.com',
176
+ * https: true,
177
+ * entry: '/src/main.js',
178
+ * staticPrefix: '',
179
+ * remotePrefixes: ['/static'],
180
+ * clearScriptCssPrefixes: '/static',
181
+ * debug: true
182
+ * });
183
+ */
184
+ declare function vueCliDevProxy(options?: ProxyOptions): VueCliConfig;
185
+
186
+ declare const _default: {
187
+ VitePluginDevProxy: typeof viteDevProxy;
188
+ VueCliPluginDevProxy: typeof vueCliDevProxy;
189
+ };
190
+
191
+ export { viteDevProxy as VitePluginDevProxy, vueCliDevProxy as VueCliPluginDevProxy, createVueCliProxyConfig, _default as default };