-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
101 lines (96 loc) · 2.94 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
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
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';
// electron
import electron from 'vite-plugin-electron';
const root = process.cwd();
function pathResolve(dir: string) {
return resolve(root, '.', dir);
}
// function isDev() {
// return process.env.NODE_ENV === "development";
// }
// https://vitejs.dev/config/
export default defineConfig({
base: './',
server: {
port: 4000,
proxy: {
// 选项写法
'/dev-api': {
target: 'http://localhost:3000',
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/dev-api/, ''),
},
},
hmr: {
overlay: false,
},
host: '0.0.0.0',
},
resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.scss', '.css'],
alias: [
{
find: /@\//,
replacement: `${pathResolve('src')}/`,
},
],
},
plugins: [
vue(),
AutoImport({
// 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
imports: ['vue'],
// 自动导入 Element Plus 相关函数,如:ElMessage, ElMessageBox... (带样式)
resolvers: [
ElementPlusResolver(),
// Auto import icon components
// 自动导入图标组件
IconsResolver({
prefix: 'Icon',
}),
],
// 输出自动导入函数等的声明
dts: resolve(__dirname, 'src/types/auto-imports.d.ts'),
// 解决eslint对于自动引入 提示报错问如:'ref' is not defined
eslintrc: {
enabled: false, // Default `false`
// provide path ending with `.mjs` or `.cjs` to generate the file with the respective format
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
},
}),
Components({
// 输出自动注册的组件的声明
dts: resolve(__dirname, 'src/types/components.d.ts'),
resolvers: [
// 自动注册 Element Plus 组件
ElementPlusResolver(),
// 自动注册图标组件 使用icon-ep-[iconName]
IconsResolver({
prefix: 'icon',
enabledCollections: ['ep'], // ep -> element-plus icon
}),
],
}),
Icons({
autoInstall: true,
}),
electron([
{
entry: 'src/electron/main.ts', // 主进程文件
vite: { build: { outDir: 'dist-electron' } },
},
{
entry: 'src/electron/modules/preload/index.ts', // preload
vite: { build: { outDir: 'dist-electron/modules/preload' } }, // 输出目录
},
]),
],
});