-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathvite.config.js
64 lines (59 loc) · 1.6 KB
/
vite.config.js
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
import { fileURLToPath, URL } from 'node:url'
import { viteSingleFile } from "vite-plugin-singlefile"
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// 获取命令行参数
const args = process.argv.slice(2);
// 解析参数为对象
const CUSTOMPARAMS = args.reduce((acc, arg) => {
const [key, value] = arg.split('=');
if (key && value) {
acc[key.replace(/^--/, '')] = value;
}
return acc;
}, {});
// https://vite.dev/config/
export default defineConfig({
define: {
CUSTOMPARAMS: JSON.stringify(CUSTOMPARAMS || {}),
},
plugins: [
vue(),
CUSTOMPARAMS.singlefile ? viteSingleFile() : null
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
},
},
build: {
// 设置输出目录
// outDir: '/Users/parapeng/Desktop/apkEditor/app/html/dist',
// emptyOutDir: true,
rollupOptions: {
output: {
// 开启代码分割
manualChunks(id) {
if (id.includes('node_modules')) {
return id.split('node_modules/')[1].split('/')[0].toString(); // 将 node_modules 按包名拆分
}
}
}
}
},
server: {
proxy: {
'/tool': {
target: 'http://localhost:80', // 后端API服务器地址
changeOrigin: false, // 是否改变源地址
configure: (proxy, options) => {
proxy.on('error', (err, req, res) => {
// 处理代理错误,返回404
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('404 Not Found, Palse open backend!');
});
}
},
},
}
})