befly-vite 1.9.0 → 1.10.0
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 +45 -77
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -10,39 +10,15 @@ import bundleAnalyzer from "vite-bundle-analyzer";
|
|
|
10
10
|
import VueDevTools from "vite-plugin-vue-devtools";
|
|
11
11
|
import VueRouter from "vue-router/vite";
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
extensions: [".vue"],
|
|
23
|
-
importMode: "async",
|
|
24
|
-
exclude: ["**/components/**"]
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 创建 Vue 插件配置
|
|
30
|
-
*/
|
|
31
|
-
function createVuePlugin() {
|
|
32
|
-
return vue({
|
|
33
|
-
script: {
|
|
34
|
-
defineModel: true,
|
|
35
|
-
propsDestructure: true
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function createTDesignResolver() {
|
|
41
|
-
return TDesignResolver({
|
|
42
|
-
library: "vue-next",
|
|
43
|
-
importStyle: "css"
|
|
44
|
-
});
|
|
45
|
-
}
|
|
13
|
+
const COMPONENTS_EXCLUDE = [/[\\/]node_modules[\\/](?!(?:.*[\\/])?befly-admin-ui[\\/])/];
|
|
14
|
+
const DEFAULT_CSS_TARGET = ["chrome107", "edge107", "firefox104", "safari16"];
|
|
15
|
+
const DEFAULT_LIGHTNINGCSS_TARGETS = {
|
|
16
|
+
chrome: 107 << 16,
|
|
17
|
+
edge: 107 << 16,
|
|
18
|
+
firefox: 104 << 16,
|
|
19
|
+
ios_saf: 16 << 16,
|
|
20
|
+
safari: 16 << 16
|
|
21
|
+
};
|
|
46
22
|
|
|
47
23
|
function normalizeResolvers(resolvers) {
|
|
48
24
|
if (resolvers === null || resolvers === undefined) {
|
|
@@ -65,10 +41,6 @@ function resolveTDesignIcon(componentName) {
|
|
|
65
41
|
}
|
|
66
42
|
}
|
|
67
43
|
|
|
68
|
-
function createComponentsInclude() {
|
|
69
|
-
return [/[\\/]src[\\/].*\.vue$/, /[\\/]node_modules[\\/]befly-admin-ui[\\/].*\.vue$/, /[\\/]packages[\\/]adminUI[\\/].*\.vue$/];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
44
|
/**
|
|
73
45
|
* 创建组件自动注册插件配置
|
|
74
46
|
*/
|
|
@@ -76,44 +48,15 @@ function createComponentsPlugin(options = {}) {
|
|
|
76
48
|
const { resolvers } = options;
|
|
77
49
|
|
|
78
50
|
return Components({
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
resolvers: [
|
|
51
|
+
// 恢复插件默认 include,保留 node_modules 排除,但放行 befly-admin-ui 内置视图
|
|
52
|
+
exclude: COMPONENTS_EXCLUDE,
|
|
53
|
+
resolvers: [TDesignResolver({ library: "vue-next", importStyle: "css" }), resolveTDesignIcon, ...normalizeResolvers(resolvers)],
|
|
82
54
|
dirs: ["src/components"],
|
|
83
55
|
deep: true,
|
|
84
56
|
dts: false
|
|
85
57
|
});
|
|
86
58
|
}
|
|
87
59
|
|
|
88
|
-
function createAnalyzerPlugin(appRoot) {
|
|
89
|
-
return bundleAnalyzer({
|
|
90
|
-
analyzerMode: "static",
|
|
91
|
-
openAnalyzer: false,
|
|
92
|
-
fileName: function () {
|
|
93
|
-
return join(appRoot, "temp", "analyzer");
|
|
94
|
-
},
|
|
95
|
-
reportTitle: "打包分析"
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function createCssCompatConfig(viteConfig) {
|
|
100
|
-
const defaultCssTarget = ["chrome107", "edge107", "firefox104", "safari16"];
|
|
101
|
-
const defaultLightningCssTargets = {
|
|
102
|
-
chrome: 107 << 16,
|
|
103
|
-
edge: 107 << 16,
|
|
104
|
-
firefox: 104 << 16,
|
|
105
|
-
ios_saf: 16 << 16,
|
|
106
|
-
safari: 16 << 16
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
cssTarget: viteConfig.build && Object.hasOwn(viteConfig.build, "cssTarget") ? viteConfig.build.cssTarget : defaultCssTarget,
|
|
111
|
-
lightningcss: {
|
|
112
|
-
targets: viteConfig.css && viteConfig.css.lightningcss && Object.hasOwn(viteConfig.css.lightningcss, "targets") ? viteConfig.css.lightningcss.targets : defaultLightningCssTargets
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
60
|
/**
|
|
118
61
|
* 创建 Befly Vite 配置
|
|
119
62
|
* @param {Object} options - 配置选项
|
|
@@ -138,23 +81,46 @@ export function createBeflyViteConfig(options = {}) {
|
|
|
138
81
|
|
|
139
82
|
// 计算根目录(如果未提供)
|
|
140
83
|
const appRoot = root || process.cwd();
|
|
141
|
-
|
|
142
84
|
const routesFolders = scanViews(appRoot);
|
|
85
|
+
const cssTarget = viteConfig.build && Object.hasOwn(viteConfig.build, "cssTarget") ? viteConfig.build.cssTarget : DEFAULT_CSS_TARGET;
|
|
86
|
+
const lightningcssTargets = viteConfig.css && viteConfig.css.lightningcss && Object.hasOwn(viteConfig.css.lightningcss, "targets") ? viteConfig.css.lightningcss.targets : DEFAULT_LIGHTNINGCSS_TARGETS;
|
|
143
87
|
|
|
144
88
|
/** @type {import('vite').Plugin[]} */
|
|
145
89
|
const plugins = [];
|
|
146
|
-
plugins.push(
|
|
147
|
-
|
|
90
|
+
plugins.push(
|
|
91
|
+
VueRouter({
|
|
92
|
+
routesFolder: routesFolders,
|
|
93
|
+
dts: false,
|
|
94
|
+
extensions: [".vue"],
|
|
95
|
+
importMode: "async",
|
|
96
|
+
exclude: ["**/components/**"]
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
plugins.push(
|
|
100
|
+
vue({
|
|
101
|
+
script: {
|
|
102
|
+
defineModel: true,
|
|
103
|
+
propsDestructure: true
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
);
|
|
148
107
|
if (devtool) {
|
|
149
108
|
plugins.push(VueDevTools());
|
|
150
109
|
}
|
|
151
110
|
plugins.push(createComponentsPlugin({ resolvers: resolvers }));
|
|
152
111
|
if (analyzer) {
|
|
153
|
-
plugins.push(
|
|
112
|
+
plugins.push(
|
|
113
|
+
bundleAnalyzer({
|
|
114
|
+
analyzerMode: "static",
|
|
115
|
+
openAnalyzer: false,
|
|
116
|
+
fileName: function () {
|
|
117
|
+
return join(appRoot, "temp", "analyzer");
|
|
118
|
+
},
|
|
119
|
+
reportTitle: "打包分析"
|
|
120
|
+
})
|
|
121
|
+
);
|
|
154
122
|
}
|
|
155
123
|
|
|
156
|
-
const cssCompatConfig = createCssCompatConfig(viteConfig);
|
|
157
|
-
|
|
158
124
|
const baseConfig = defineConfig({
|
|
159
125
|
base: "./",
|
|
160
126
|
|
|
@@ -174,7 +140,7 @@ export function createBeflyViteConfig(options = {}) {
|
|
|
174
140
|
build: {
|
|
175
141
|
outDir: "dist",
|
|
176
142
|
assetsDir: "assets",
|
|
177
|
-
cssTarget:
|
|
143
|
+
cssTarget: cssTarget,
|
|
178
144
|
rolldownOptions:
|
|
179
145
|
manualChunks === undefined
|
|
180
146
|
? undefined
|
|
@@ -188,7 +154,9 @@ export function createBeflyViteConfig(options = {}) {
|
|
|
188
154
|
|
|
189
155
|
css: {
|
|
190
156
|
transformer: "lightningcss",
|
|
191
|
-
lightningcss:
|
|
157
|
+
lightningcss: {
|
|
158
|
+
targets: lightningcssTargets
|
|
159
|
+
}
|
|
192
160
|
},
|
|
193
161
|
|
|
194
162
|
optimizeDeps: {
|