befly-vite 1.5.17 → 1.5.19
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/index.browser.js +37 -53
- package/index.js +3 -9
- package/package.json +4 -4
package/index.browser.js
CHANGED
|
@@ -7,6 +7,36 @@
|
|
|
7
7
|
* @property {Record<string, any>=} meta
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
function normalizeRouteSegment(segment) {
|
|
11
|
+
if (segment.startsWith(":")) {
|
|
12
|
+
return segment;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return segment
|
|
16
|
+
.replace(/_/g, "-")
|
|
17
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
18
|
+
.toLowerCase();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function resolveRoutePath(path, parentPath = "") {
|
|
22
|
+
const rawPath = String(path || "");
|
|
23
|
+
const match = rawPath.match(/_(\d+)$/);
|
|
24
|
+
const cleanPath = match ? rawPath.slice(0, match.index) : rawPath;
|
|
25
|
+
const routePath =
|
|
26
|
+
cleanPath === "index"
|
|
27
|
+
? ""
|
|
28
|
+
: cleanPath
|
|
29
|
+
.split("/")
|
|
30
|
+
.filter(Boolean)
|
|
31
|
+
.map((segment) => normalizeRouteSegment(segment))
|
|
32
|
+
.join("/");
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
layoutName: match ? match[1] : "",
|
|
36
|
+
path: `/${[parentPath, routePath].filter(Boolean).join("/")}`.replace(/\/+/g, "/")
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
10
40
|
/**
|
|
11
41
|
* 内部实现:根据文件名后缀 _数字 判断使用哪个布局,并直接输出最终路由。
|
|
12
42
|
*
|
|
@@ -14,66 +44,22 @@
|
|
|
14
44
|
*
|
|
15
45
|
* @param {RouteConfig[]} routes
|
|
16
46
|
* @param {(layoutName: string) => any} resolveLayoutComponent
|
|
47
|
+
* @param {import('vue-router').RouteRecordRaw[]} result
|
|
17
48
|
* @param {string=} parentPath
|
|
18
49
|
* @param {string=} inheritLayout
|
|
19
|
-
* @returns {import('vue-router').RouteRecordRaw[]}
|
|
20
50
|
*/
|
|
21
|
-
function
|
|
22
|
-
const rawPath = String(path || "");
|
|
23
|
-
const match = rawPath.match(/_(\d+)$/);
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
layoutName: match ? match[1] : "",
|
|
27
|
-
path: match ? rawPath.slice(0, match.index) : rawPath
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function normalizeRoutePath(path) {
|
|
32
|
-
return String(path || "")
|
|
33
|
-
.split("/")
|
|
34
|
-
.filter(Boolean)
|
|
35
|
-
.map((segment) => {
|
|
36
|
-
if (segment.startsWith(":")) {
|
|
37
|
-
return segment;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return segment
|
|
41
|
-
.replace(/_/g, "-")
|
|
42
|
-
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
43
|
-
.toLowerCase();
|
|
44
|
-
})
|
|
45
|
-
.join("/");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function joinRoutePath(parentPath, childPath) {
|
|
49
|
-
if (!parentPath) {
|
|
50
|
-
return childPath;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (!childPath) {
|
|
54
|
-
return parentPath;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return `${parentPath}/${childPath}`;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function buildLayoutRoutes(routes, resolveLayoutComponent, parentPath = "", inheritLayout = "") {
|
|
61
|
-
/** @type {import('vue-router').RouteRecordRaw[]} */
|
|
62
|
-
const result = [];
|
|
63
|
-
|
|
51
|
+
function appendLayoutRoutes(routes, resolveLayoutComponent, result, parentPath = "", inheritLayout = "") {
|
|
64
52
|
for (const route of routes) {
|
|
65
|
-
const { layoutName, path } =
|
|
53
|
+
const { layoutName, path } = resolveRoutePath(route.path, parentPath);
|
|
66
54
|
const currentLayout = layoutName || inheritLayout;
|
|
67
|
-
const currentPath = path === "index" ? "" : normalizeRoutePath(path);
|
|
68
|
-
const fullPath = joinRoutePath(parentPath, currentPath);
|
|
69
55
|
|
|
70
56
|
if (route.children && route.children.length > 0) {
|
|
71
|
-
|
|
57
|
+
appendLayoutRoutes(route.children, resolveLayoutComponent, result, path, currentLayout);
|
|
72
58
|
continue;
|
|
73
59
|
}
|
|
74
60
|
|
|
75
61
|
result.push({
|
|
76
|
-
path:
|
|
62
|
+
path: path,
|
|
77
63
|
component: resolveLayoutComponent(currentLayout || "default"),
|
|
78
64
|
meta: route.meta,
|
|
79
65
|
children: [
|
|
@@ -84,8 +70,6 @@ function buildLayoutRoutes(routes, resolveLayoutComponent, parentPath = "", inhe
|
|
|
84
70
|
]
|
|
85
71
|
});
|
|
86
72
|
}
|
|
87
|
-
|
|
88
|
-
return result;
|
|
89
73
|
}
|
|
90
74
|
|
|
91
75
|
/**
|
|
@@ -110,8 +94,8 @@ export function Layouts(routes, rootRedirectPath, resolveLayoutComponent) {
|
|
|
110
94
|
}
|
|
111
95
|
|
|
112
96
|
const trimmedRootRedirectPath = typeof rootRedirectPath === "string" ? rootRedirectPath.trim() : "";
|
|
113
|
-
|
|
114
|
-
|
|
97
|
+
const layoutRoutes = [];
|
|
98
|
+
appendLayoutRoutes(routes, resolveLayoutComponent, layoutRoutes);
|
|
115
99
|
|
|
116
100
|
if (trimmedRootRedirectPath && trimmedRootRedirectPath !== "/") {
|
|
117
101
|
return [
|
package/index.js
CHANGED
|
@@ -7,7 +7,6 @@ import AutoImport from "unplugin-auto-import/vite";
|
|
|
7
7
|
import { TDesignResolver } from "unplugin-vue-components/resolvers";
|
|
8
8
|
import Components from "unplugin-vue-components/vite";
|
|
9
9
|
import bundleAnalyzer from "vite-bundle-analyzer";
|
|
10
|
-
import VueDevTools from "vite-plugin-vue-devtools";
|
|
11
10
|
import { defineConfig, mergeConfig } from "vite";
|
|
12
11
|
import { VueRouterAutoImports } from "vue-router/unplugin";
|
|
13
12
|
import VueRouter from "vue-router/vite";
|
|
@@ -88,10 +87,6 @@ function createComponentsPlugin() {
|
|
|
88
87
|
});
|
|
89
88
|
}
|
|
90
89
|
|
|
91
|
-
function createDevToolsPlugin() {
|
|
92
|
-
return VueDevTools();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
90
|
function createAnalyzerPlugin(appRoot) {
|
|
96
91
|
return bundleAnalyzer({
|
|
97
92
|
analyzerMode: "static",
|
|
@@ -107,7 +102,7 @@ function createAnalyzerPlugin(appRoot) {
|
|
|
107
102
|
* 创建 Befly Vite 配置
|
|
108
103
|
* @param {Object} options - 配置选项
|
|
109
104
|
* @param {string} options.root - 项目根目录(可选)
|
|
110
|
-
* @param {boolean} options.devtool - 是否启用
|
|
105
|
+
* @param {boolean} options.devtool - 是否启用 Vite 8 内置 devtools(可选,默认 false)
|
|
111
106
|
* @param {boolean} options.analyzer - 是否启用 vite-bundle-analyzer(可选,默认 false)
|
|
112
107
|
* @param {Object} options.resolvers - 自定义 resolvers(可选)
|
|
113
108
|
* @param {Function} options.manualChunks - 自定义分包配置(可选)
|
|
@@ -133,9 +128,6 @@ export function createBeflyViteConfig(options = {}) {
|
|
|
133
128
|
const plugins = [];
|
|
134
129
|
plugins.push(createRouterPlugin({ routesFolders: routesFolders }));
|
|
135
130
|
plugins.push(createVuePlugin());
|
|
136
|
-
if (devtool) {
|
|
137
|
-
plugins.push(createDevToolsPlugin());
|
|
138
|
-
}
|
|
139
131
|
plugins.push(createAutoImportPlugin({ resolvers: resolvers }));
|
|
140
132
|
plugins.push(createComponentsPlugin({ resolvers: resolvers }));
|
|
141
133
|
if (analyzer) {
|
|
@@ -145,6 +137,8 @@ export function createBeflyViteConfig(options = {}) {
|
|
|
145
137
|
const baseConfig = defineConfig({
|
|
146
138
|
base: "./",
|
|
147
139
|
|
|
140
|
+
devtools: devtool,
|
|
141
|
+
|
|
148
142
|
plugins: plugins,
|
|
149
143
|
|
|
150
144
|
resolve: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly-vite",
|
|
3
|
-
"version": "1.5.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "1.5.19",
|
|
4
|
+
"gitHead": "9f262d5515b1990c215e39285dedce3016d29d5c",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly Vite 配置预设和插件集合",
|
|
7
7
|
"keywords": [
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"registry": "https://registry.npmjs.org"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@vitejs/devtools": "^0.1.2",
|
|
36
37
|
"@vitejs/plugin-vue": "^6.0.5",
|
|
37
38
|
"sass": "^1.98.0",
|
|
38
39
|
"unplugin-auto-import": "^21.0.0",
|
|
39
40
|
"unplugin-vue-components": "^31.0.0",
|
|
40
|
-
"vite-bundle-analyzer": "^1.3.6"
|
|
41
|
-
"vite-plugin-vue-devtools": "^8.1.0"
|
|
41
|
+
"vite-bundle-analyzer": "^1.3.6"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"bun": ">=1.3.0"
|