@keyblade/vite-plugin-vue-pro 1.0.11 → 1.0.13
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.
|
@@ -9,6 +9,8 @@ export interface LogPageRouteOptions {
|
|
|
9
9
|
* 开发环境下,在控制台输出当前访问页面对应的源码文件路径(可点击跳转)。
|
|
10
10
|
*
|
|
11
11
|
* 由前端注入脚本上报当前路由,服务端根据路由解析对应的 .vue 文件:
|
|
12
|
-
* 依次尝试 `<basePath>/<route>/index.vue` 与 `<basePath>/<route>.vue
|
|
12
|
+
* 依次尝试 `<basePath>/<route>/index.vue` 与 `<basePath>/<route>.vue`;
|
|
13
|
+
* 若末段含连字符(如 `route-search-query-detail` 实际对应 `route-search-query/detail.vue`),
|
|
14
|
+
* 还会把连字符当作潜在的目录分隔符逐一尝试。
|
|
13
15
|
*/
|
|
14
16
|
export default function logPageRoute(options?: LogPageRouteOptions): Plugin;
|
|
@@ -1,50 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
for (const
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
11
|
-
return
|
|
1
|
+
import y from "node:fs";
|
|
2
|
+
import r from "node:path";
|
|
3
|
+
const S = "POST";
|
|
4
|
+
function R(m) {
|
|
5
|
+
const { basePath: u = "src/views", outputPrefix: f = "web" } = m || {};
|
|
6
|
+
let h = "";
|
|
7
|
+
function g(o) {
|
|
8
|
+
for (const t of o) {
|
|
9
|
+
const e = r.resolve(process.cwd(), t);
|
|
10
|
+
if (y.existsSync(e))
|
|
11
|
+
return t.replace(/\\/g, "/");
|
|
12
12
|
}
|
|
13
13
|
return "";
|
|
14
14
|
}
|
|
15
|
+
function v(o) {
|
|
16
|
+
if (!o)
|
|
17
|
+
return g([r.join(u, "index.vue")]);
|
|
18
|
+
const t = o.split("/"), e = t.pop() || "", i = t.join("/"), l = [
|
|
19
|
+
r.join(u, i, e, "index.vue"),
|
|
20
|
+
r.join(u, i, `${e}.vue`)
|
|
21
|
+
], s = e.split("-");
|
|
22
|
+
for (let n = s.length - 1; n >= 1; n--) {
|
|
23
|
+
const a = s.slice(0, n).join("-"), c = s.slice(n).join("-");
|
|
24
|
+
l.push(r.join(u, i, a, `${c}.vue`)), l.push(r.join(u, i, a, c, "index.vue"));
|
|
25
|
+
}
|
|
26
|
+
return g(l);
|
|
27
|
+
}
|
|
15
28
|
return {
|
|
16
29
|
name: "keyblade-pro-log-page-route",
|
|
17
30
|
enforce: "pre",
|
|
18
31
|
apply: "serve",
|
|
19
|
-
configureServer(
|
|
20
|
-
|
|
21
|
-
if (
|
|
32
|
+
configureServer(o) {
|
|
33
|
+
o.middlewares.use("/__log_page_route", (t, e, i) => {
|
|
34
|
+
if (t.method !== S)
|
|
22
35
|
return i();
|
|
23
|
-
const
|
|
36
|
+
const l = 1e3 * 10, s = setTimeout(() => {
|
|
24
37
|
e.statusCode = 504, e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ success: !1, error: "Gateway Timeout" }));
|
|
25
|
-
},
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}),
|
|
38
|
+
}, l);
|
|
39
|
+
let n = "";
|
|
40
|
+
t.on("data", (a) => {
|
|
41
|
+
n += a;
|
|
42
|
+
}), t.on("end", () => {
|
|
30
43
|
try {
|
|
31
|
-
const { route: a } = JSON.parse(
|
|
32
|
-
if (
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
clearTimeout(
|
|
44
|
+
const { route: a } = JSON.parse(n), c = a.replace(/^\//, "").replace(/\/$/, "").split("?")[0], d = v(c);
|
|
45
|
+
if (d) {
|
|
46
|
+
const p = f ? r.join(f, d).replace(/\\/g, "/") : d;
|
|
47
|
+
if (p === h) {
|
|
48
|
+
clearTimeout(s), e.statusCode = 200, e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ success: !0 }));
|
|
36
49
|
return;
|
|
37
50
|
}
|
|
38
|
-
|
|
51
|
+
h = p, console.info(`\x1B[32m➜ \x1B[37m正在访问: \x1B[36m${p}\x1B[0m`);
|
|
39
52
|
}
|
|
40
53
|
} catch (a) {
|
|
41
54
|
}
|
|
42
|
-
clearTimeout(
|
|
55
|
+
clearTimeout(s), e.statusCode = 200, e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ success: !0 }));
|
|
43
56
|
});
|
|
44
57
|
});
|
|
45
58
|
},
|
|
46
|
-
transformIndexHtml(
|
|
47
|
-
return
|
|
59
|
+
transformIndexHtml(o) {
|
|
60
|
+
return o.replace("</head>", `
|
|
48
61
|
<script>
|
|
49
62
|
(function() {
|
|
50
63
|
if (window.__logPageRouteInitialized) return;
|
|
@@ -126,5 +139,5 @@ function S(f) {
|
|
|
126
139
|
};
|
|
127
140
|
}
|
|
128
141
|
export {
|
|
129
|
-
|
|
142
|
+
R as default
|
|
130
143
|
};
|
package/package.json
CHANGED