-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
109 lines (105 loc) · 3.19 KB
/
vite.config.ts
File metadata and controls
109 lines (105 loc) · 3.19 KB
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
import react from '@vitejs/plugin-react';
import * as path from 'path';
import svgr from 'vite-plugin-svgr';
import qiankun from 'vite-plugin-qiankun';
import electron from 'vite-electron-plugin';
import { customStart, loadViteEnv } from 'vite-electron-plugin/plugin';
import { defineConfig } from 'vite';
import { rmSync } from 'node:fs';
import viteCompression from 'vite-plugin-compression';
import { VitePWA } from 'vite-plugin-pwa';
import pkg from './package.json';
rmSync(path.join(__dirname, 'dist-electron'), { recursive: true, force: true });
const isDevelopment = process.env.NODE_ENV === 'development' || !!process.env.VSCODE_DEBUG;
const isProduction = process.env.NODE_ENV === 'production';
export default defineConfig({
build: {
sourcemap: true,
outDir: 'dist',
assetsDir: 'static/img/',
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
const arr = id.toString().split('node_modules/')[1].split('/');
switch (arr[0]) {
case '@react':
return '_' + arr[0];
break;
default:
return '__vendor';
break;
}
}
},
chunkFileNames: 'static/js1/[name]-[hash].js',
entryFileNames: 'static/js2/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]'
}
}
},
resolve: {
// 設置別名
alias: {
'@': path.resolve(__dirname, 'src'),
'@pages': path.resolve(__dirname, 'src/pages'),
'@assets': path.resolve(__dirname, 'src/assets'),
'@comps': path.resolve(__dirname, 'src/components'),
'@utils': path.resolve(__dirname, 'src/utils'),
'@router': path.resolve(__dirname, 'src/router'),
'@store': path.resolve(__dirname, 'src/store'),
'@tools': path.resolve(__dirname, 'src/tools'),
'@plugins': path.resolve(__dirname, 'src/plugins'),
'@icon': path.resolve(__dirname, 'src/icons'),
'@css': path.resolve(__dirname, 'src/css')
}
},
plugins: [
react(),
svgr(),
qiankun('remote-assistance-code', {
// 微前端應用名,主應用接口名需一致
useDevMode: true
}),
VitePWA({
registerType: 'autoUpdate',
devOptions: {
enabled: true
}
}),
electron({
include: ['electron'],
transformOptions: {
sourcemap: isDevelopment
},
plugins: [
...(!!process.env.VSCODE_DEBUG
? [
customStart(() =>
debounce(() => console.log(/* For `.vscode/.debug.script.mjs` */ '[startup] Electron App'))
)
]
: []),
loadViteEnv()
]
}),
viteCompression()
],
server: !!process.env.VSCODE_DEBUG
? (() => {
const url = new URL(pkg.debug.env.VITE_DEV_SERVER_URL);
return {
host: url.hostname,
port: +url.port
};
})()
: undefined,
clearScreen: false
});
function debounce<Fn extends (...args: any[]) => void>(fn: Fn, delay = 299): Fn {
let t: NodeJS.Timeout;
return ((...args: Parameters<Fn>) => {
clearTimeout(t);
t = setTimeout(() => fn(...args), delay);
}) as Fn;
}