From 763087b119193f8aa587bcbc3d778ac9d0c88352 Mon Sep 17 00:00:00 2001
From: LCJ-MinYa <1049468118@qq.com>
Date: Thu, 12 Jun 2025 14:51:21 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20webpack=E5=B0=86=E5=A4=9A=E4=B8=AAjs?=
=?UTF-8?q?=E6=96=87=E4=BB=B6=E6=89=93=E5=8C=85=E4=B8=BA=E4=B8=80=E4=B8=AA?=
=?UTF-8?q?js=E6=96=87=E4=BB=B6=EF=BC=88=E5=B0=86node=E5=8C=85=E8=BD=AC?=
=?UTF-8?q?=E4=B8=BA=E6=9C=AC=E5=9C=B0=E5=BC=95=E5=85=A5=E6=96=B9=E6=A1=88?=
=?UTF-8?q?=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/router/modules/demo.ts | 3 ++-
src/utils/tools.ts | 19 +++++++++++++++++--
src/views/demo/buildCli/buildCli.md | 1 +
src/views/demo/buildCli/buildCli.vue | 18 ++++++++++++++++++
4 files changed, 38 insertions(+), 3 deletions(-)
create mode 100644 src/views/demo/buildCli/buildCli.md
create mode 100644 src/views/demo/buildCli/buildCli.vue
diff --git a/src/router/modules/demo.ts b/src/router/modules/demo.ts
index cd5cafb..3bc2bd3 100644
--- a/src/router/modules/demo.ts
+++ b/src/router/modules/demo.ts
@@ -121,12 +121,13 @@ const demoRoutes = Object.keys(components).map((path) => {
const isHasIndex = path.includes('/index.vue');
let cptPath = path.replace(route.FILE_NAME_PREFIX, '');
cptPath = isHasIndex ? cptPath.replace('/index.vue', '') : cptPath.replace('.vue', '');
+ cptPath = route.mergeDuplicatePathSegments(cptPath);
return {
path: cptPath,
name: route.convertPathToName(cptPath),
component: components[path],
meta: {
- title: route.getTitleFromPathStr(titleArr, cptPath),
+ title: route.getTitleFromPathStr(titleArr, cptPath, '/demo/'),
},
};
});
diff --git a/src/utils/tools.ts b/src/utils/tools.ts
index 3c8b689..b90dfc5 100644
--- a/src/utils/tools.ts
+++ b/src/utils/tools.ts
@@ -39,9 +39,24 @@ export const route = {
.map((part) => part.charAt(0).toUpperCase() + part.slice(1)) // 首字母大写
.join(''); // 连接成字符串
},
- getTitleFromPathStr: (arr: any, path: string): string => {
+ getTitleFromPathStr: (arr: any, path: string, ignoreFields: string = ''): string => {
const item = arr.find(({ key }) => path.includes(key));
- return item ? item.title : path; // 如果找到,返回 title;否则返回 null
+ return item ? item.title : path.replace(ignoreFields, ''); // 如果找到,返回 title;否则返回 null
+ },
+ mergeDuplicatePathSegments(path: string) {
+ // 移除开头和结尾的斜杠,然后按斜杠分割
+ const segments = path.replace(/^\/|\/$/g, '').split('/');
+
+ // 如果最后两个段相同且至少有2个段
+ if (segments.length >= 2 && segments[segments.length - 1] === segments[segments.length - 2]) {
+ // 移除最后一个段
+ segments.pop();
+ // 重新组合路径
+ return '/' + segments.join('/');
+ }
+
+ // 不需要处理的情况,返回原路径
+ return path;
},
};
diff --git a/src/views/demo/buildCli/buildCli.md b/src/views/demo/buildCli/buildCli.md
new file mode 100644
index 0000000..e4c5a82
--- /dev/null
+++ b/src/views/demo/buildCli/buildCli.md
@@ -0,0 +1 @@
+## 请参考demoBuildCli目录演示
\ No newline at end of file
diff --git a/src/views/demo/buildCli/buildCli.vue b/src/views/demo/buildCli/buildCli.vue
new file mode 100644
index 0000000..7cf3c34
--- /dev/null
+++ b/src/views/demo/buildCli/buildCli.vue
@@ -0,0 +1,18 @@
+
+
+
+
+