-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
122 lines (121 loc) · 3.11 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
import { parse } from 'node:url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { exec } from 'child_process';
import tailwindcss from 'tailwindcss';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { fileURLToPath, URL } from 'node:url';
import postcssPresetEnv from 'postcss-preset-env';
import vueDevTools from 'vite-plugin-vue-devtools';
export default defineConfig({
css: {
postcss: {
plugins: [
tailwindcss(),
postcssPresetEnv({
stage: 4,
}),
],
},
},
plugins: [
vue(),
vueJsx(),
vueDevTools(),
{
name: 'run-powershell-command',
configureServer(server) {
server.middlewares.use('/api/exec', (req, res) => {
if (process.env.NODE_ENV === 'development') {
const queryObject = parse(req.url as string, true).query;
const command = queryObject.cmd as string; // 默认命令
const shell = process.platform === 'win32' ? 'powershell.exe' : '/bin/bash';
if (command) {
exec(
command,
{
shell,
},
(error, stdout, stderr) => {
if (error) {
res.statusCode = 500;
res.end(`Error: ${error.message}`);
return;
}
if (stderr) {
res.statusCode = 500;
res.end(`Error: ${stderr}`);
return;
}
res.statusCode = 200;
res.end(stdout); // 返回命令执行结果
},
);
} else {
res.statusCode = 500;
res.end(`Error: unknow command`);
}
}
});
},
},
// visualizer({
// open: true,
// gzipSize: false
// }),
// legacy({
// targets: ['defaults', 'not IE 11', 'chrome >= 87', 'android >= 5.0'],
// additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
// renderLegacyChunks: true,
// polyfills: [
// 'es.symbol',
// 'es.promise',
// 'es.promise.finally',
// 'es/map',
// 'es/set',
// 'es.array.filter',
// 'es.array.for-each',
// 'es.array.flat-map',
// 'es.object.define-properties',
// 'es.object.define-property',
// 'es.object.get-own-property-descriptor',
// 'es.object.get-own-property-descriptors',
// 'es.object.keys',
// 'es.object.to-string',
// 'web.dom-collections.for-each',
// 'esnext.global-this',
// 'esnext.string.match-all'
// ]
// })
],
build: {
minify:'terser',
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('pako')) {
return 'pako';
}
if (id.includes('iconfont')) {
return 'iconfont';
}
if (id.includes('lodash')) {
return 'lodash';
}
if (id.includes('hooks')) {
return 'hooks';
}
if (id.includes('apis')) {
return 'apis';
}
}
}
}
},
assetsInclude: ['**/*.xml'], // 添加这一行以包括 XML 文件
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
});