@xysfe/vite-plugin-dev-proxy 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 CHANGED
@@ -1,4 +1,4 @@
1
- # vite-plugin-dev-proxy
1
+ # @xysfe/vite-plugin-dev-proxy
2
2
 
3
3
  A Vite plugin for development environment proxy that automatically proxies remote server requests and handles HTML responses.
4
4
 
@@ -9,6 +9,8 @@ A Vite plugin for development environment proxy that automatically proxies remot
9
9
  - 🍪 Automatic cookie rewriting, removing Secure and Domain attributes
10
10
  - 🔀 Redirect handling with protocol mismatch fixes
11
11
  - ⚙️ Support for custom static resource prefixes
12
+ - 🎯 Flexible script/link tag filtering with string, array, regex, or function
13
+ - 🏷️ Custom placeholder replacement for development script injection
12
14
  - 🐛 Debug logging support
13
15
  - 🔗 Merge with other proxy configurations
14
16
  - 🔧 TypeScript support with full type definitions
@@ -16,15 +18,15 @@ A Vite plugin for development environment proxy that automatically proxies remot
16
18
  ## Installation
17
19
 
18
20
  ```bash
19
- npm install vite-plugin-dev-proxy --save-dev
21
+ npm install @xysfe/vite-plugin-dev-proxy --save-dev
20
22
  ```
21
23
 
22
24
  ```bash
23
- yarn add vite-plugin-dev-proxy --dev
25
+ yarn add @xysfe/vite-plugin-dev-proxy --dev
24
26
  ```
25
27
 
26
28
  ```bash
27
- pnpm add vite-plugin-dev-proxy --save-dev
29
+ pnpm add @xysfe/vite-plugin-dev-proxy --save-dev
28
30
  ```
29
31
 
30
32
  ## Usage
@@ -34,7 +36,7 @@ pnpm add vite-plugin-dev-proxy --save-dev
34
36
  ```js
35
37
  // vite.config.js
36
38
  import { defineConfig } from "vite";
37
- import viteDevProxy from "vite-plugin-dev-proxy";
39
+ import viteDevProxy from "@xysfe/vite-plugin-dev-proxy";
38
40
 
39
41
  export default defineConfig({
40
42
  plugins: [
@@ -50,7 +52,7 @@ export default defineConfig({
50
52
  ```js
51
53
  // vite.config.js
52
54
  import { defineConfig } from "vite";
53
- import viteDevProxy from "vite-plugin-dev-proxy";
55
+ import viteDevProxy from "@xysfe/vite-plugin-dev-proxy";
54
56
 
55
57
  export default defineConfig({
56
58
  plugins: [
@@ -59,7 +61,9 @@ export default defineConfig({
59
61
  https: true,
60
62
  staticPrefix: "/dev/static",
61
63
  bypassPrefixes: ["/static"],
62
- scriptCssPrefix: "/static/global",
64
+ clearScriptCssPrefixes: "/static/global",
65
+ developmentAgentOccupancy:
66
+ "<!-- Vite development mode proxy occupancy -->",
63
67
  entry: "/src/main.js",
64
68
  debug: true,
65
69
  }),
@@ -67,6 +71,32 @@ export default defineConfig({
67
71
  });
68
72
  ```
69
73
 
74
+ ### Advanced Usage: Custom Script/Link Filtering
75
+
76
+ ```js
77
+ // vite.config.js
78
+ import { RegeExp } from "vite";
79
+ import viteDevProxy from "@xysfe/vite-plugin-dev-proxy";
80
+
81
+ export default defineConfig({
82
+ plugins: [
83
+ viteDevProxy({
84
+ appHost: "example.com",
85
+ // Filter by string prefix
86
+ clearScriptCssPrefixes: "/static/global",
87
+ // Or filter by multiple prefixes
88
+ clearScriptCssPrefixes: ["/static/global", "/cdn/assets"],
89
+ // Or filter by regex
90
+ clearScriptCssPrefixes: /cdn\.example\.com/,
91
+ // Or filter by custom function
92
+ clearScriptCssPrefixes: (match) => {
93
+ return match.includes("remove-me");
94
+ },
95
+ }),
96
+ ],
97
+ });
98
+ ```
99
+
70
100
  ### Coexisting with Other Proxy Configurations
71
101
 
72
102
  ```js
@@ -93,17 +123,18 @@ export default defineConfig({
93
123
 
94
124
  #### Options
95
125
 
96
- | Parameter | Type | Default | Required | Description |
97
- | ----------------- | ---------- | ---------------- | -------- | ----------------------------------------------------------------------------------------------- |
98
- | `appHost` | `string` | - | ✅ | Target server address |
99
- | `https` | `boolean` | `true` | - | Whether to use HTTPS for the target server |
100
- | `staticPrefix` | `string` | `''` | - | Static resource prefix, used to build local entry path |
101
- | `bypassPrefixes` | `string[]` | `['/static']` | - | List of prefixes to bypass proxy, requests matching these prefixes will access remote resources |
102
- | `scriptCssPrefix` | `string` | `''` | - | Script/CSS prefix, used to precisely match remote scripts and stylesheets to remove |
103
- | `entry` | `string` | `'/src/main.js'` | - | Local development entry file path |
104
- | `isLib` | `boolean` | `false` | - | Whether in component library mode, returns local HTML file when true |
105
- | `localIndexHtml` | `string` | `'index.html'` | - | Local HTML file path (only used when isLib=true) |
106
- | `debug` | `boolean` | `false` | - | Whether to enable debug logging |
126
+ | Parameter | Type | Default | Required | Description |
127
+ | --------------------------- | ------------------------------------------ | ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
128
+ | `appHost` | `string` | - | ✅ | Target server address |
129
+ | `https` | `boolean` | `true` | - | Whether to be HTTPS for the target server |
130
+ | `staticPrefix` | `string` | `''` | - | Static resource prefix, used to build local entry path |
131
+ | `bypassPrefixes` | `string[]` | `['/static']` | - | List of prefixes to bypass proxy, requests matching these prefixes will access remote resources |
132
+ | `clearScriptCssPrefixes` | `string \| string[] \| RegExp \| Function` | `''` | - | Filter script/link tags to remove. Supports string prefix, array of prefixes, regex, or custom function |
133
+ | `developmentAgentOccupancy` | `string` | `''` | - | Custom placeholder string to replace with local development script. If not set, script will be injected into div with id="app" |
134
+ | `entry` | `string` | `'/src/main.js'` | - | Local development entry file path |
135
+ | `isLib` | `boolean` | `false` | - | Whether in component library mode, returns local HTML file when true |
136
+ | `localIndexHtml` | `string` | `'index.html'` | - | Local HTML file path (only used when isLib=true) |
137
+ | `debug` | `boolean` | `false` | - | Whether to enable debug logging |
107
138
 
108
139
  ## How It Works
109
140
 
@@ -115,9 +146,15 @@ The plugin injects `server.proxy` configuration through Vite's `config` hook, pr
115
146
 
116
147
  When detecting a browser page navigation request and the response is HTML:
117
148
 
118
- - Removes remote `type="module" crossorigin` script tags
119
- - Removes remote `crossorigin` stylesheet link tags
120
- - Inserts local development script entry
149
+ - Matches all `<script>` and `<link>` tags in the HTML
150
+ - Removes tags based on `clearScriptCssPrefixes` configuration:
151
+ - If string: removes tags where src/href starts with the prefix
152
+ - If array: removes tags where src/href starts with any of the prefixes
153
+ - If RegExp: removes tags matching the regex pattern
154
+ - If Function: removes tags where the function returns true
155
+ - Inserts local development script entry:
156
+ - If `developmentAgentOccupancy` is set, replaces that placeholder with the local script
157
+ - Otherwise, injects the local script into `<div id="app">` element
121
158
 
122
159
  ### 3. Cookie Rewriting
123
160
 
@@ -142,8 +179,7 @@ viteDevProxy({
142
179
  Log output example:
143
180
 
144
181
  ```
145
- vite-plugin-dev-proxy: staticPrefix /dev/static
146
- vite-plugin-dev-proxy: scriptCssPrefix /static/global
182
+ @xysfe/vite-plugin-dev-proxy: staticPrefix /dev/static
147
183
  Proxy request: /admin/index (5ms)
148
184
  HTML processed: /admin/index (23ms)
149
185
  Bypass proxy: /static/js/app.js
@@ -155,7 +191,7 @@ Redirect handled: https://example.com/login -> http://localhost:3003/login (3ms)
155
191
  This plugin is written in TypeScript and provides full type definitions. You can import types for better development experience:
156
192
 
157
193
  ```typescript
158
- import viteDevProxy, { ProxyOptions } from "vite-plugin-dev-proxy";
194
+ import viteDevProxy, { ProxyOptions } from "@xysfe/vite-plugin-dev-proxy";
159
195
 
160
196
  const config: ProxyOptions = {
161
197
  appHost: "example.com",
@@ -173,7 +209,8 @@ export default defineConfig({
173
209
  1. `appHost` is a required parameter, not providing it will throw an error
174
210
  2. The plugin will override `server.proxy` configuration in `vite.config.js`
175
211
  3. Ensure the local development server port matches the port in redirect handling
176
- 4. Use `scriptCssPrefix` to precisely control which remote scripts and stylesheets to remove
212
+ 4. Use `clearScriptCssPrefixes` to flexibly control which remote scripts and stylesheets to remove
213
+ 5. Use `developmentAgentOccupancy` to specify a custom placeholder for script injection, or let the plugin automatically inject into `<div id="app">`
177
214
 
178
215
  ## Requirements
179
216
 
@@ -190,4 +227,4 @@ Contributions are welcome! Please feel free to submit a Pull Request.
190
227
 
191
228
  ## Issues
192
229
 
193
- If you encounter any issues, please report them on [GitHub Issues](https://github.com/CNLHB/vite-plugin-dev-proxy/issues).
230
+ If you encounter any issues, please report them on [GitHub Issues](https://github.com/CNLHB/@xysfe/vite-plugin-dev-proxy/issues).
package/dist/index.cjs CHANGED
@@ -218,6 +218,9 @@ function viteDevProxy(options = {}) {
218
218
  return {
219
219
  name: "vite-plugin-dev-proxy",
220
220
  config: (viteConfig) => {
221
+ if (process.env.NODE_ENV !== "development") {
222
+ return {};
223
+ }
221
224
  const pluginProxy = createProxyConfig(options);
222
225
  const existingProxy = viteConfig.server?.proxy || {};
223
226
  const mergedProxy = {
package/dist/index.mjs CHANGED
@@ -211,6 +211,9 @@ function viteDevProxy(options = {}) {
211
211
  return {
212
212
  name: "vite-plugin-dev-proxy",
213
213
  config: (viteConfig) => {
214
+ if (process.env.NODE_ENV !== "development") {
215
+ return {};
216
+ }
214
217
  const pluginProxy = createProxyConfig(options);
215
218
  const existingProxy = viteConfig.server?.proxy || {};
216
219
  const mergedProxy = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xysfe/vite-plugin-dev-proxy",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A Vite plugin for development environment proxy that automatically proxies remote server requests and handles HTML responses",
5
5
  "files": [
6
6
  "dist"