befly-vite 1.0.1 → 1.0.3
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.js +52 -30
- package/package.json +3 -2
- package/plugins/icons.js +1 -1
- package/plugins/router.js +3 -2
- package/utils/{scanBeflyAddonViews.js → scanBeflyViews.js} +16 -4
package/index.js
CHANGED
|
@@ -15,49 +15,56 @@ import { createInspectPlugin } from './plugins/inspect.js';
|
|
|
15
15
|
* 默认分包策略
|
|
16
16
|
*/
|
|
17
17
|
function defaultManualChunks(id) {
|
|
18
|
-
// Vue
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
// Vue 生态系统 - 使用更严格的匹配确保独立打包
|
|
19
|
+
// 注意:必须在 befly-addon 之前判断,因为 addon 会引用这些库
|
|
20
|
+
|
|
21
|
+
// vue-router(优先级最高)
|
|
22
|
+
if (id.match(/node_modules[\/\\]vue-router[\/\\]/)) {
|
|
23
|
+
return 'vue-router';
|
|
21
24
|
}
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
|
|
26
|
+
// pinia
|
|
27
|
+
if (id.match(/node_modules[\/\\]pinia[\/\\]/)) {
|
|
28
|
+
return 'pinia';
|
|
24
29
|
}
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
|
|
31
|
+
// vue 核心和运行时(@vue/* 包)
|
|
32
|
+
if (id.match(/node_modules[\/\\](vue[\/\\]|@vue[\/\\])/)) {
|
|
33
|
+
return 'vue';
|
|
27
34
|
}
|
|
28
35
|
|
|
29
36
|
// TDesign Vue Next
|
|
30
|
-
if (id.includes('
|
|
37
|
+
if (id.includes('tdesign-vue-next')) {
|
|
31
38
|
return 'tdesign';
|
|
32
39
|
}
|
|
33
40
|
|
|
34
41
|
// 工具库
|
|
35
|
-
if (id.
|
|
36
|
-
return '
|
|
42
|
+
if (id.match(/node_modules[\/\\]axios[\/\\]/)) {
|
|
43
|
+
return 'axios';
|
|
37
44
|
}
|
|
38
|
-
if (id.
|
|
39
|
-
return '
|
|
45
|
+
if (id.match(/node_modules[\/\\]lodash-es[\/\\]/)) {
|
|
46
|
+
return 'lodash';
|
|
40
47
|
}
|
|
41
48
|
|
|
42
49
|
// echarts
|
|
43
|
-
if (id.
|
|
44
|
-
return '
|
|
50
|
+
if (id.match(/node_modules[\/\\]echarts[\/\\]/)) {
|
|
51
|
+
return 'echarts';
|
|
45
52
|
}
|
|
46
|
-
if (id.
|
|
47
|
-
return '
|
|
53
|
+
if (id.match(/node_modules[\/\\]zrender[\/\\]/)) {
|
|
54
|
+
return 'zrender';
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
// 图标
|
|
51
|
-
if (id.includes('
|
|
58
|
+
if (id.includes('/@iconify/') || id.includes('~icons/')) {
|
|
52
59
|
return 'icons';
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
// Vue Macros
|
|
56
|
-
if (id.
|
|
63
|
+
if (id.match(/node_modules[\/\\](@vue-macros|vue-macros)[\/\\]/)) {
|
|
57
64
|
return 'vue-macros';
|
|
58
65
|
}
|
|
59
66
|
|
|
60
|
-
// befly-addon
|
|
67
|
+
// befly-addon(必须在 Vue 判断之后)
|
|
61
68
|
if (id.includes('@befly-addon/') || id.includes('packages/addonAdmin/') || id.includes('packages\\addonAdmin\\')) {
|
|
62
69
|
return 'befly-addon';
|
|
63
70
|
}
|
|
@@ -119,21 +126,36 @@ export function createBeflyViteConfig(options = {}) {
|
|
|
119
126
|
sourcemap: false,
|
|
120
127
|
minify: 'esbuild',
|
|
121
128
|
chunkSizeWarningLimit: 1000,
|
|
129
|
+
commonjsOptions: {
|
|
130
|
+
include: [/node_modules/],
|
|
131
|
+
transformMixedEsModules: true
|
|
132
|
+
},
|
|
122
133
|
rollupOptions: {
|
|
123
134
|
output: {
|
|
124
135
|
chunkFileNames: 'assets/js/[name]-[hash].js',
|
|
125
136
|
entryFileNames: 'assets/js/[name]-[hash].js',
|
|
126
137
|
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
|
|
127
|
-
manualChunks
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
manualChunks(id) {
|
|
139
|
+
// 最高优先级:框架库必须单独打包
|
|
140
|
+
if (id.includes('node_modules')) {
|
|
141
|
+
// vue-router
|
|
142
|
+
if (id.includes('/vue-router/')) return 'vue-router';
|
|
143
|
+
// pinia
|
|
144
|
+
if (id.includes('/pinia/')) return 'pinia';
|
|
145
|
+
// vue 核心(包括 @vue/*)
|
|
146
|
+
if (id.includes('/vue/') || id.includes('/@vue/')) return 'vue';
|
|
147
|
+
// tdesign
|
|
148
|
+
if (id.includes('/tdesign-vue-next/')) return 'tdesign';
|
|
149
|
+
// axios
|
|
150
|
+
if (id.includes('/axios/')) return 'axios';
|
|
151
|
+
// 其他第三方库
|
|
152
|
+
return 'vendor';
|
|
153
|
+
}
|
|
154
|
+
// befly-addon(workspace 包)
|
|
155
|
+
if (id.includes('@befly-addon/') || id.includes('/addonAdmin/')) {
|
|
156
|
+
return 'befly-addon';
|
|
157
|
+
}
|
|
158
|
+
}
|
|
137
159
|
}
|
|
138
160
|
}
|
|
139
161
|
},
|
|
@@ -150,7 +172,7 @@ export function createBeflyViteConfig(options = {}) {
|
|
|
150
172
|
export { createUnoConfig } from './configs/uno.config.js';
|
|
151
173
|
|
|
152
174
|
// 导出工具函数
|
|
153
|
-
export {
|
|
175
|
+
export { scanBeflyViews } from './utils/scanBeflyViews.js';
|
|
154
176
|
|
|
155
177
|
// 导出所有插件创建函数(供高级用户自定义)
|
|
156
178
|
export { createVuePlugins } from './plugins/vue.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly-vite",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Befly Vite 配置预设和插件集合",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@unocss/preset-uno": "^66.5.6",
|
|
38
38
|
"@vitejs/plugin-vue": "^6.0.1",
|
|
39
39
|
"@vue-macros/reactivity-transform": "^3.1.1",
|
|
40
|
+
"sass": "^1.94.0",
|
|
40
41
|
"unocss": "^66.5.6",
|
|
41
42
|
"unplugin-auto-import": "^20.2.0",
|
|
42
43
|
"unplugin-icons": "^22.5.0",
|
|
@@ -54,5 +55,5 @@
|
|
|
54
55
|
"engines": {
|
|
55
56
|
"bun": ">=1.3.0"
|
|
56
57
|
},
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "afb329b2cce2ab5f5821d8515ae7dba4622a4f1f"
|
|
58
59
|
}
|
package/plugins/icons.js
CHANGED
package/plugins/router.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import VueRouter from 'unplugin-vue-router/vite';
|
|
2
|
+
import { scanBeflyViews } from '../utils/scanBeflyViews.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 创建路由插件配置
|
|
5
6
|
*/
|
|
6
7
|
export function createRouterPlugin(options = {}) {
|
|
7
|
-
const { scanViews } = options;
|
|
8
|
+
const { scanViews = scanBeflyViews } = options;
|
|
8
9
|
|
|
9
10
|
return VueRouter({
|
|
10
|
-
routesFolder: scanViews
|
|
11
|
+
routesFolder: scanViews(),
|
|
11
12
|
dts: './src/types/typed-router.d.ts',
|
|
12
13
|
extensions: ['.vue'],
|
|
13
14
|
importMode: 'async',
|
|
@@ -2,17 +2,28 @@ import { readdirSync, existsSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 扫描项目和所有 @befly-addon 包的 views 目录
|
|
6
6
|
* 用于 unplugin-vue-router 的 routesFolder 配置
|
|
7
|
-
*
|
|
7
|
+
* 注意:此函数只能在 vite.config.js 中使用(Node.js 环境),不能在浏览器中使用
|
|
8
8
|
* @returns 路由文件夹配置数组
|
|
9
9
|
*/
|
|
10
|
-
export function
|
|
10
|
+
export function scanBeflyViews() {
|
|
11
11
|
// 使用绝对路径:基于项目根目录(process.cwd())
|
|
12
12
|
const projectRoot = process.cwd();
|
|
13
13
|
const addonBasePath = join(projectRoot, 'node_modules', '@befly-addon');
|
|
14
14
|
const routesFolders = [];
|
|
15
15
|
|
|
16
|
+
// 1. 先添加项目自己的 views 目录
|
|
17
|
+
const projectViewsPath = join(projectRoot, 'src', 'views');
|
|
18
|
+
if (existsSync(projectViewsPath)) {
|
|
19
|
+
routesFolders.push({
|
|
20
|
+
src: projectViewsPath,
|
|
21
|
+
path: '',
|
|
22
|
+
exclude: ['**/components/**']
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 2. 扫描 @befly-addon 包的 views 目录
|
|
16
27
|
if (!existsSync(addonBasePath)) {
|
|
17
28
|
return routesFolders;
|
|
18
29
|
}
|
|
@@ -31,7 +42,8 @@ export function scanBeflyAddonViews() {
|
|
|
31
42
|
if (existsSync(viewsPath)) {
|
|
32
43
|
routesFolders.push({
|
|
33
44
|
src: viewsPath,
|
|
34
|
-
path: `addon/${addonName}
|
|
45
|
+
path: `addon/${addonName}/`,
|
|
46
|
+
exclude: ['**/components/**']
|
|
35
47
|
});
|
|
36
48
|
}
|
|
37
49
|
}
|