-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
98 lines (97 loc) · 2.92 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import vitePluginImp from "vite-plugin-imp";
import { visualizer } from "rollup-plugin-visualizer";
import legacy from "@vitejs/plugin-legacy";
import Unocss from "unocss/vite";
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), "");
return {
resolve: {
alias: [
{
find: "@",
replacement: "/src",
},
],
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@import "@/styles/variables";',
},
},
},
esbuild:
mode === "production"
? {
drop: ["debugger"],
pure: [
"console.log",
"console.warn",
"console.debug",
"console.trace",
],
}
: {},
build: {
minify: "esbuild",
// vite默认代码混淆使用esbuild,调用上面esbuild的配置项,但是发现@vitejs/plugin-legacy并没有生效,查看源码也并未发现问题,
// 但是经过测试下来疑似@vitejs/plugin-legacy仍然使用terser混淆,故仍然保留terserOptions选项,未来如确定不再使用terser可移除该项
terserOptions: {
compress: {
keep_infinity: true,
drop_console: true,
drop_debugger: true,
},
},
},
plugins: [
vue(),
vitePluginImp({
libList: [
{
libName: "vant",
replaceOldImport: false,
style: (name) => {
const specialMapList = [
["showToast", "toast"],
["show-toast", "toast"],
["showLoadingToast", "toast"],
["show-loading-toast", "toast"],
["showSuccessToast", "toast"],
["show-success-toast", "toast"],
["showFailToast", "toast"],
["show-fail-toast", "toast"],
["closeToast", "toast"],
["close-toast", "toast"],
["showDialog", "dialog"],
["show-dialog", "dialog"],
["showConfirmDialog", "dialog"],
["show-confirm-dialog", "dialog"],
["closeDialog", "dialog"],
["close-dialog", "dialog"],
["show-notify", "notify"],
["close-notify", "notify"],
];
const specialMap = specialMapList.find(
(element) => element[0] === name,
);
if (specialMap) {
return `vant/es/${specialMap[1]}/style/index`;
} else {
return `vant/es/${name}/style/index`;
}
},
},
],
}),
legacy({
targets: ["defaults", "not IE 11"],
}),
visualizer(),
Unocss(),
],
};
});