feat: webpack将多个js文件打包为一个js文件(将node包转为本地引入方案)

master
LCJ-MinYa 7 months ago
parent 3ab05a8746
commit 763087b119

@ -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/'),
},
};
});

@ -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;
},
};

@ -0,0 +1 @@
## 请参考demoBuildCli目录演示

@ -0,0 +1,18 @@
<template>
<div
class="markdown-body"
v-html="htmlStr"
/>
</template>
<script setup>
import { ref } from 'vue';
import { marked } from 'marked';
import { getMarkdownContent } from '@/utils/tools';
const htmlStr = ref('');
getMarkdownContent('./md/buildCli.md').then((res) => {
htmlStr.value = marked(res);
});
</script>
Loading…
Cancel
Save