befly-vite 1.5.9 → 1.5.15
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 +28 -31
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -6,28 +6,12 @@ import vue from "@vitejs/plugin-vue";
|
|
|
6
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
|
-
import
|
|
9
|
+
import bundleAnalyzer from "vite-bundle-analyzer";
|
|
10
10
|
import VueDevTools from "vite-plugin-vue-devtools";
|
|
11
11
|
import { defineConfig, mergeConfig } from "vite";
|
|
12
12
|
import { VueRouterAutoImports } from "vue-router/unplugin";
|
|
13
13
|
import VueRouter from "vue-router/vite";
|
|
14
14
|
|
|
15
|
-
function parseBooleanEnv(value, defaultValue) {
|
|
16
|
-
if (value === undefined || value === null || value === "") {
|
|
17
|
-
return defaultValue;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const normalized = String(value).trim().toLowerCase();
|
|
21
|
-
if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return defaultValue;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
15
|
/**
|
|
32
16
|
* 创建路由插件配置
|
|
33
17
|
*/
|
|
@@ -65,7 +49,8 @@ function createAutoImportPlugin() {
|
|
|
65
49
|
imports: ["vue", "pinia", VueRouterAutoImports],
|
|
66
50
|
resolvers: [
|
|
67
51
|
TDesignResolver({
|
|
68
|
-
library: "vue-next"
|
|
52
|
+
library: "vue-next",
|
|
53
|
+
importStyle: "css"
|
|
69
54
|
})
|
|
70
55
|
],
|
|
71
56
|
dts: false,
|
|
@@ -88,11 +73,12 @@ function resolveTDesignIcon(componentName) {
|
|
|
88
73
|
*/
|
|
89
74
|
function createComponentsPlugin() {
|
|
90
75
|
return Components({
|
|
91
|
-
//
|
|
92
|
-
include: [/[\\/]src[\\/].*\.vue$/],
|
|
76
|
+
// 给 admin 自身源码和 befly-admin-ui 视图做组件自动注册;addon 视图强制手动导入
|
|
77
|
+
include: [/[\\/]src[\\/].*\.vue$/, /[\\/]node_modules[\\/]befly-admin-ui[\\/].*\.vue$/],
|
|
93
78
|
resolvers: [
|
|
94
79
|
TDesignResolver({
|
|
95
|
-
library: "vue-next"
|
|
80
|
+
library: "vue-next",
|
|
81
|
+
importStyle: "css"
|
|
96
82
|
}),
|
|
97
83
|
resolveTDesignIcon
|
|
98
84
|
],
|
|
@@ -106,10 +92,14 @@ function createDevToolsPlugin() {
|
|
|
106
92
|
return VueDevTools();
|
|
107
93
|
}
|
|
108
94
|
|
|
109
|
-
function createAnalyzerPlugin() {
|
|
110
|
-
return
|
|
111
|
-
analyzerMode: "
|
|
112
|
-
openAnalyzer: false
|
|
95
|
+
function createAnalyzerPlugin(appRoot) {
|
|
96
|
+
return bundleAnalyzer({
|
|
97
|
+
analyzerMode: "static",
|
|
98
|
+
openAnalyzer: false,
|
|
99
|
+
fileName: function () {
|
|
100
|
+
return join(appRoot, "temp", "analyzer");
|
|
101
|
+
},
|
|
102
|
+
reportTitle: "打包分析"
|
|
113
103
|
});
|
|
114
104
|
}
|
|
115
105
|
|
|
@@ -117,32 +107,39 @@ function createAnalyzerPlugin() {
|
|
|
117
107
|
* 创建 Befly Vite 配置
|
|
118
108
|
* @param {Object} options - 配置选项
|
|
119
109
|
* @param {string} options.root - 项目根目录(可选)
|
|
110
|
+
* @param {boolean} options.devtool - 是否启用 vite-plugin-vue-devtools(可选,默认 false)
|
|
111
|
+
* @param {boolean} options.analyzer - 是否启用 vite-bundle-analyzer(可选,默认 false)
|
|
120
112
|
* @param {Object} options.resolvers - 自定义 resolvers(可选)
|
|
121
113
|
* @param {Function} options.manualChunks - 自定义分包配置(可选)
|
|
122
114
|
* @param {Object} options.viteConfig - 用户自定义配置(可选)
|
|
123
115
|
* @returns {Object} Vite 配置对象
|
|
124
116
|
*/
|
|
125
117
|
export function createBeflyViteConfig(options = {}) {
|
|
126
|
-
const {
|
|
118
|
+
const {
|
|
119
|
+
//
|
|
120
|
+
root,
|
|
121
|
+
devtool = false,
|
|
122
|
+
analyzer = false,
|
|
123
|
+
resolvers = {},
|
|
124
|
+
viteConfig = {}
|
|
125
|
+
} = options;
|
|
127
126
|
|
|
128
127
|
// 计算根目录(如果未提供)
|
|
129
128
|
const appRoot = root || process.cwd();
|
|
130
129
|
|
|
131
130
|
const routesFolders = scanViews(appRoot);
|
|
132
|
-
const enableDevTools = parseBooleanEnv(process.env.VITE_ENABLE_DEVTOOLS, false);
|
|
133
|
-
const enableAnalyzer = parseBooleanEnv(process.env.VITE_ENABLE_ANALYZER, false);
|
|
134
131
|
|
|
135
132
|
/** @type {import('vite').Plugin[]} */
|
|
136
133
|
const plugins = [];
|
|
137
134
|
plugins.push(createRouterPlugin({ routesFolders: routesFolders }));
|
|
138
135
|
plugins.push(createVuePlugin());
|
|
139
|
-
if (
|
|
136
|
+
if (devtool) {
|
|
140
137
|
plugins.push(createDevToolsPlugin());
|
|
141
138
|
}
|
|
142
139
|
plugins.push(createAutoImportPlugin({ resolvers: resolvers }));
|
|
143
140
|
plugins.push(createComponentsPlugin({ resolvers: resolvers }));
|
|
144
|
-
if (
|
|
145
|
-
plugins.push(createAnalyzerPlugin());
|
|
141
|
+
if (analyzer) {
|
|
142
|
+
plugins.push(createAnalyzerPlugin(appRoot));
|
|
146
143
|
}
|
|
147
144
|
|
|
148
145
|
const baseConfig = defineConfig({
|
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.15",
|
|
4
|
+
"gitHead": "ba7fa7cc0534c48de2df4970d69a14853cf6b2a6",
|
|
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/plugin-vue": "^6.0.
|
|
37
|
-
"sass": "^1.
|
|
36
|
+
"@vitejs/plugin-vue": "^6.0.5",
|
|
37
|
+
"sass": "^1.98.0",
|
|
38
38
|
"unplugin-auto-import": "^21.0.0",
|
|
39
39
|
"unplugin-vue-components": "^31.0.0",
|
|
40
40
|
"vite-bundle-analyzer": "^1.3.6",
|
|
41
|
-
"vite-plugin-vue-devtools": "^8.0
|
|
41
|
+
"vite-plugin-vue-devtools": "^8.1.0"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
44
|
"bun": ">=1.3.0"
|