-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
129 lines (122 loc) · 3.29 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
119
120
121
122
123
124
125
126
127
128
129
/*
* @Author: HxB
* @Date: 2023-04-27 10:08:57
* @LastEditors: DoubleAm
* @LastEditTime: 2023-12-29 15:32:51
* @Description: vite 配置文件
* @FilePath: \web_mods_base\vite.config.ts
*/
import * as path from 'path';
import { defineConfig } from 'vite';
import reactPlugin from '@vitejs/plugin-react';
import eslint from 'vite-plugin-eslint';
import electronPlugin from 'vite-plugin-electron';
// 若需设置 process.env 的值可以通过 set 关键字传入 vite 中
// eslint-disable-next-line no-undef
const getPath = (_path) => path.resolve(__dirname, _path);
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
console.table({ command, mode });
const pluginsConfig = [
eslint({
fix: true,
}),
reactPlugin(),
];
if (mode === 'electron') {
pluginsConfig.push(
electronPlugin([
{
entry: [
'electron/main.ts',
'electron/preload.ts',
'electron/updater.ts',
'electron/events.ts',
'electron/utils.ts',
'electron/controller.ts',
'electron/store.ts',
],
vite: {
build: {
chunkSizeWarningLimit: 2048,
outDir: 'build/electron',
minify: 'terser',
},
},
},
]),
);
}
return {
root: getPath('./'),
base: './',
build: {
chunkSizeWarningLimit: 2048,
target: 'modules',
outDir: 'build',
assetsDir: 'assets',
// vite 3.0.0+ 需要安装 terser
minify: 'terser',
terserOptions: {
// 生产环境去除 console
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
// 作为静态资源服务的文件夹,并且始终按原样提供或复制而无需进行转换。
publicDir: getPath('resource'),
resolve: {
alias: {
'@': getPath('main'),
'@resource': getPath('resource'),
'@_custom': getPath('main/_custom'),
'@static': getPath('main/static'),
'@router': getPath('main/router'),
'@tools': getPath('main/tools'),
'@services': getPath('main/services'),
'@components': getPath('main/components'),
'@views': getPath('main/views'),
'@store': getPath('main/store'),
},
},
preview: {
// vite preview --port=9527 --host
port: 9527,
},
server: {
cors: true,
// 在开发服务器启动时自动在浏览器中打开应用程序
open: mode === 'development',
hmr: true,
host: true,
port: 1998,
proxy: {
'^/api': {
target: 'http://192.168.110.168',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '/api/test/'),
},
'^/upload': {
target: 'http://a.biugle.cn',
changeOrigin: true,
},
'^/test/api/.*': {
target: 'http://192.168.110.168',
changeOrigin: true,
},
},
},
css: {
preprocessorOptions: {
less: {
charset: false,
javascriptEnabled: true,
additionalData: '@import "@_custom/css/global.less";', // 全局变量导入到每个 less 文件中
},
},
},
plugins: pluginsConfig,
};
});