forked from IoTSharp/IoTSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
102 lines (100 loc) · 2.84 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
import path from 'path';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import { defineConfig, loadEnv, ConfigEnv } from 'vite';
import WindiCSS from 'vite-plugin-windicss';
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Icons from 'unplugin-icons/vite';
import IconsResolver from 'unplugin-icons/resolver';
const pathResolve = (dir: string): any => {
return resolve(__dirname, '.', dir);
};
const pathSrc = path.resolve(__dirname, 'src');
const alias: Record<string, string> = {
'/@': pathResolve('./src/'),
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
};
const viteConfig = defineConfig((mode: ConfigEnv) => {
const env = loadEnv(mode.mode, process.cwd());
return {
plugins: [
vue(),
WindiCSS(),
AutoImport({
imports: ['vue', 'vue-router', 'pinia'],
dirs: ['./stores'],
eslintrc: {
enabled: true, // Default `false`
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
},
resolvers: [
ElementPlusResolver(),
// Auto import icon components
// 自动导入图标组件
IconsResolver({
prefix: 'Icon',
}),
],
dts: path.resolve(pathSrc, 'auto-imports.d.ts'),
}),
Components({
resolvers: [
// Auto register icon components
// 自动注册图标组件
IconsResolver({
prefix: 'icon',
}),
ElementPlusResolver(),
],
dts: path.resolve(pathSrc, 'components.d.ts'),
}),
Icons({
compiler: 'vue3',
autoInstall: true,
}),
],
root: process.cwd(),
resolve: { alias },
base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
hmr: true,
optimizeDeps: {
include: [
'element-plus/dist/locale/zh-cn.mjs',
'element-plus/dist/locale/en.mjs',
'monaco-editor/esm/vs/language/json/json.worker',
'monaco-editor/esm/vs/language/css/css.worker',
'monaco-editor/esm/vs/language/html/html.worker',
'monaco-editor/esm/vs/language/typescript/ts.worker',
'monaco-editor/esm/vs/editor/editor.worker',
],
},
server: {
host: '0.0.0.0',
port: env.VITE_PORT as unknown as number,
},
esbuild: {
drop: mode.mode === 'production' ? ['console', 'debugger'] : [],
},
build: {
rollupOptions: {
output: {
compact: true,
manualChunks: {
vue: ['vue', 'vue-router', 'pinia'],
echarts: ['echarts'],
},
},
},
},
css: { preprocessorOptions: { css: { charset: false } } },
define: {
__VUE_I18N_LEGACY_API__: JSON.stringify(false),
__VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
__INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
},
};
});
export default viteConfig;