-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
118 lines (112 loc) · 2.75 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import replace from "@rollup/plugin-replace";
import vue from "@vitejs/plugin-vue";
import { fileURLToPath, URL } from "node:url";
import AutoImport from "unplugin-auto-import/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
import Components from "unplugin-vue-components/vite";
import { PluginOption } from "vite";
import { DirResolverHelper } from "vite-auto-import-resolvers";
import compressPlugin from "vite-plugin-compression";
import { defineConfig } from "vitest/config";
// @ts-ignore
import packageJson from "./package.json";
// https://vitejs.dev/config/
export default defineConfig({
test: {
globals: true,
environment: "happy-dom",
},
base: "./",
server: {
host: "0.0.0.0",
proxy: {},
},
build: {
chunkSizeWarningLimit: 512 * 1024,
},
define: {
__VUE_I18N_FULL_INSTALL__: false,
__VUE_I18N_LEGACY_API__: true,
__INTLIFY_PROD_DEVTOOLS__: false,
},
plugins: [
vue(),
createReplacePlugin(),
DirResolverHelper(),
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/, // .vue
/\.md$/, // .md
],
imports: [
"vue",
"vue-router",
// "vitest",
"@vueuse/core",
{
"naive-ui": [
"useDialog",
"useMessage",
"useNotification",
"useLoadingBar",
"NButton",
"NDropdown",
"NAvatar",
"NModal",
],
},
],
}),
Components({
resolvers: [NaiveUiResolver()],
}),
// configCompressPlugin("gzip", false),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
optimizeDeps: {
include: ["vue", "vue-router", "naive-ui"],
},
});
function createReplacePlugin(isProd = true) {
const isDEV = !isProd;
return replace({
preventAssignment: true,
values: {
__DEV__: isDEV ? "true" : "false",
__PROD__: isProd ? "true" : "false",
"false || ": "",
__VERSION__: packageJson.version,
},
});
}
export function configCompressPlugin(
compress: "gzip" | "brotli" | "none",
deleteOriginFile = false
): PluginOption[] {
const compressList = compress.split(",");
const plugins: PluginOption[] = [];
if (compressList.includes("gzip")) {
plugins.push(
compressPlugin({
ext: ".gz",
deleteOriginFile,
})
);
}
if (compressList.includes("brotli")) {
plugins.push(
compressPlugin({
ext: ".br",
algorithm: "brotliCompress",
deleteOriginFile,
})
);
}
return plugins;
}