@keyblade/vite-plugin-vue-pro 1.0.10 → 1.0.12
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/es/index.d.ts +5 -0
- package/es/index.js +13 -11
- package/es/plugins/log-page-route.d.ts +14 -0
- package/es/plugins/log-page-route.js +131 -0
- package/package.json +1 -1
package/es/index.d.ts
CHANGED
|
@@ -2,12 +2,15 @@ import { PluginOption } from 'vite';
|
|
|
2
2
|
import { Options as VueOptions } from '@vitejs/plugin-vue';
|
|
3
3
|
import { VitePluginVueDevToolsOptions } from 'vite-plugin-vue-devtools';
|
|
4
4
|
import { visualizer } from 'rollup-plugin-visualizer';
|
|
5
|
+
import { default as logPageRoute, LogPageRouteOptions } from './plugins/log-page-route';
|
|
6
|
+
export { logPageRoute, type LogPageRouteOptions };
|
|
5
7
|
export default function framework(options?: {
|
|
6
8
|
/** 是否禁用 */
|
|
7
9
|
disable?: {
|
|
8
10
|
vue?: boolean;
|
|
9
11
|
vueDevTools?: boolean;
|
|
10
12
|
visualizer?: boolean;
|
|
13
|
+
logPageRoute?: boolean;
|
|
11
14
|
};
|
|
12
15
|
/** vue 配置 */
|
|
13
16
|
vue?: VueOptions;
|
|
@@ -15,4 +18,6 @@ export default function framework(options?: {
|
|
|
15
18
|
vueDevTools?: VitePluginVueDevToolsOptions;
|
|
16
19
|
/** 打包分析 配置 */
|
|
17
20
|
visualizer?: Parameters<typeof visualizer>[0];
|
|
21
|
+
/** 开发环境页面路由日志 配置 */
|
|
22
|
+
logPageRoute?: LogPageRouteOptions;
|
|
18
23
|
}): PluginOption[];
|
package/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var g = (r, u, e) => new Promise((c, a) => {
|
|
2
|
+
var l = (f) => {
|
|
3
3
|
try {
|
|
4
4
|
m(e.next(f));
|
|
5
5
|
} catch (v) {
|
|
@@ -11,14 +11,15 @@ var c = (r, u, e) => new Promise((l, a) => {
|
|
|
11
11
|
} catch (v) {
|
|
12
12
|
a(v);
|
|
13
13
|
}
|
|
14
|
-
}, m = (f) => f.done ?
|
|
14
|
+
}, m = (f) => f.done ? c(f.value) : Promise.resolve(f.value).then(l, h);
|
|
15
15
|
m((e = e.apply(r, u)).next());
|
|
16
16
|
});
|
|
17
|
-
import
|
|
17
|
+
import t from "@vitejs/plugin-vue";
|
|
18
18
|
import y from "vite-plugin-vue-devtools";
|
|
19
|
-
import { monitorUsage as
|
|
19
|
+
import { monitorUsage as P } from "@foundbyte/security-monitor-usage";
|
|
20
20
|
import { visualizer as z } from "rollup-plugin-visualizer";
|
|
21
|
-
|
|
21
|
+
import D from "./plugins/log-page-route.js";
|
|
22
|
+
function R() {
|
|
22
23
|
return {
|
|
23
24
|
/** 名称 */
|
|
24
25
|
name: "keyblade-pro-security-monitor",
|
|
@@ -26,16 +27,17 @@ function D() {
|
|
|
26
27
|
enforce: "post",
|
|
27
28
|
/** 启动时执行 */
|
|
28
29
|
buildStart() {
|
|
29
|
-
return
|
|
30
|
-
yield
|
|
30
|
+
return g(this, null, function* () {
|
|
31
|
+
yield P("未知");
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
+
function U(r) {
|
|
36
37
|
const { disable: u } = r || {}, e = [];
|
|
37
|
-
return u != null && u.vue || e.push(
|
|
38
|
+
return u != null && u.vue || e.push(t(r == null ? void 0 : r.vue)), u != null && u.vueDevTools || e.push(y(r == null ? void 0 : r.vueDevTools)), u != null && u.visualizer || e.push(z(r == null ? void 0 : r.visualizer)), u != null && u.logPageRoute || e.push(D(r == null ? void 0 : r.logPageRoute)), e.push(R()), e;
|
|
38
39
|
}
|
|
39
40
|
export {
|
|
40
|
-
|
|
41
|
+
U as default,
|
|
42
|
+
D as logPageRoute
|
|
41
43
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
export interface LogPageRouteOptions {
|
|
3
|
+
/** 页面源码目录,相对于 vite 项目根目录,默认 'src/views' */
|
|
4
|
+
basePath?: string;
|
|
5
|
+
/** 输出路径前缀,用于拼接控制台可点击路径,默认 'web' */
|
|
6
|
+
outputPrefix?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 开发环境下,在控制台输出当前访问页面对应的源码文件路径(可点击跳转)。
|
|
10
|
+
*
|
|
11
|
+
* 由前端注入脚本上报当前路由,服务端根据路由解析对应的 .vue 文件:
|
|
12
|
+
* 依次尝试 `<basePath>/<route>/index.vue` 与 `<basePath>/<route>.vue`。
|
|
13
|
+
*/
|
|
14
|
+
export default function logPageRoute(options?: LogPageRouteOptions): Plugin;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import y from "node:fs";
|
|
2
|
+
import n from "node:path";
|
|
3
|
+
const v = "POST";
|
|
4
|
+
function T(f) {
|
|
5
|
+
const { basePath: r = "src/views", outputPrefix: l = "web" } = f || {};
|
|
6
|
+
let c = "";
|
|
7
|
+
function h(t) {
|
|
8
|
+
const o = t ? [n.join(r, t, "index.vue"), n.join(r, `${t}.vue`)] : [n.join(r, "index.vue")];
|
|
9
|
+
for (const e of o) {
|
|
10
|
+
const i = n.resolve(process.cwd(), e);
|
|
11
|
+
if (y.existsSync(i))
|
|
12
|
+
return e.replace(/\\/g, "/");
|
|
13
|
+
}
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
name: "keyblade-pro-log-page-route",
|
|
18
|
+
enforce: "pre",
|
|
19
|
+
apply: "serve",
|
|
20
|
+
configureServer(t) {
|
|
21
|
+
t.middlewares.use("/__log_page_route", (o, e, i) => {
|
|
22
|
+
if (o.method !== v)
|
|
23
|
+
return i();
|
|
24
|
+
const g = 1e3 * 10, d = setTimeout(() => {
|
|
25
|
+
e.statusCode = 504, e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ success: !1, error: "Gateway Timeout" }));
|
|
26
|
+
}, g);
|
|
27
|
+
let p = "";
|
|
28
|
+
o.on("data", (a) => {
|
|
29
|
+
p += a;
|
|
30
|
+
}), o.on("end", () => {
|
|
31
|
+
try {
|
|
32
|
+
const { route: a } = JSON.parse(p), m = a.replace(/^\//, "").replace(/\/$/, "").split("?")[0], s = h(m);
|
|
33
|
+
if (s) {
|
|
34
|
+
const u = l ? n.join(l, s).replace(/\\/g, "/") : s;
|
|
35
|
+
if (u === c) {
|
|
36
|
+
clearTimeout(d), e.statusCode = 200, e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ success: !0 }));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
c = u, console.info(`\x1B[32m➜ \x1B[37m正在访问: \x1B[36m${u}\x1B[0m`);
|
|
40
|
+
}
|
|
41
|
+
} catch (a) {
|
|
42
|
+
}
|
|
43
|
+
clearTimeout(d), e.statusCode = 200, e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ success: !0 }));
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
transformIndexHtml(t) {
|
|
48
|
+
return t.replace("</head>", `
|
|
49
|
+
<script>
|
|
50
|
+
(function() {
|
|
51
|
+
if (window.__logPageRouteInitialized) return;
|
|
52
|
+
window.__logPageRouteInitialized = true;
|
|
53
|
+
|
|
54
|
+
function getRoute() {
|
|
55
|
+
var hash = location.hash;
|
|
56
|
+
if (hash && hash.length > 1) {
|
|
57
|
+
return hash.slice(1).split('?')[0];
|
|
58
|
+
}
|
|
59
|
+
var pathname = location.pathname;
|
|
60
|
+
return (pathname || '/').split('?')[0];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var lastRoute = '';
|
|
64
|
+
var lastHref = location.href;
|
|
65
|
+
var sendTimer = null;
|
|
66
|
+
|
|
67
|
+
function doSend(route) {
|
|
68
|
+
var data = JSON.stringify({ route: route });
|
|
69
|
+
if (navigator.sendBeacon) {
|
|
70
|
+
navigator.sendBeacon('/__log_page_route', new Blob([data], { type: 'application/json' }));
|
|
71
|
+
} else {
|
|
72
|
+
fetch('/__log_page_route', {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: { 'Content-Type': 'application/json' },
|
|
75
|
+
body: data,
|
|
76
|
+
keepalive: true
|
|
77
|
+
}).catch(function() {});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function sendRoute() {
|
|
82
|
+
var route = getRoute();
|
|
83
|
+
if (!route) {
|
|
84
|
+
route = '/';
|
|
85
|
+
}
|
|
86
|
+
route = route.replace(/\\/$/, '') || '/';
|
|
87
|
+
if (route === lastRoute) return;
|
|
88
|
+
lastRoute = route;
|
|
89
|
+
|
|
90
|
+
if (sendTimer) clearTimeout(sendTimer);
|
|
91
|
+
sendTimer = setTimeout(function() {
|
|
92
|
+
doSend(route);
|
|
93
|
+
}, 100);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (document.readyState === 'loading') {
|
|
97
|
+
document.addEventListener('DOMContentLoaded', sendRoute);
|
|
98
|
+
} else {
|
|
99
|
+
sendRoute();
|
|
100
|
+
}
|
|
101
|
+
window.addEventListener('hashchange', sendRoute);
|
|
102
|
+
var originalPushState = history.pushState;
|
|
103
|
+
var originalReplaceState = history.replaceState;
|
|
104
|
+
history.pushState = function() {
|
|
105
|
+
originalPushState.apply(history, arguments);
|
|
106
|
+
var newHref = location.href;
|
|
107
|
+
if (newHref !== lastHref) {
|
|
108
|
+
lastHref = newHref;
|
|
109
|
+
sendRoute();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
history.replaceState = function() {
|
|
113
|
+
originalReplaceState.apply(history, arguments);
|
|
114
|
+
var newHref = location.href;
|
|
115
|
+
if (newHref !== lastHref) {
|
|
116
|
+
lastHref = newHref;
|
|
117
|
+
sendRoute();
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
window.addEventListener('popstate', function() {
|
|
121
|
+
lastHref = location.href;
|
|
122
|
+
sendRoute();
|
|
123
|
+
});
|
|
124
|
+
})();
|
|
125
|
+
<\/script>` + "</head>");
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export {
|
|
130
|
+
T as default
|
|
131
|
+
};
|
package/package.json
CHANGED