-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvite.config.ts
100 lines (98 loc) · 2.58 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
/// <reference types="vite-plugin-electron/electron-env" />
import { rmSync } from 'node:fs'
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import electron from 'vite-plugin-electron'
import renderer from 'vite-plugin-electron-renderer'
import pkg from './package.json'
import electronPath from 'electron'
import { spawn } from 'child_process'
export default defineConfig(() => {
rmSync('dist-electron', { recursive: true, force: true })
return {
plugins: [
vue(),
AutoImport({ resolvers: [ElementPlusResolver()], dts: false }),
Components({ resolvers: [ElementPlusResolver()], dts: false }),
electron([
{
entry: 'electron/index.ts',
onstart() {
if (process.electronApp) {
process.electronApp.removeAllListeners()
process.electronApp.kill()
}
process.electronApp = spawn(electronPath as unknown as string, ['.', '--no-sandbox'])
process.electronApp.once('exit', process.exit)
// 解决中文乱码问题
process.electronApp.stdout?.on('data', (data) => {
const str = data.toString().trim()
str && console.log(str)
})
process.electronApp.stderr?.on('data', (data) => {
const str = data.toString().trim()
str && console.error(str)
})
},
vite: {
build: {
sourcemap: false,
minify: true,
outDir: 'dist-electron',
target: 'node16',
chunkSizeWarningLimit: Infinity,
reportCompressedSize: false,
rollupOptions: {
external: Object.keys('dependencies' in pkg ? pkg.dependencies : {})
}
}
}
}
]),
electron([
{
entry: 'electron/ahk.ts',
onstart() {
},
vite: {
build: {
sourcemap: false,
minify: false,
outDir: 'dist-electron',
target: 'node16',
chunkSizeWarningLimit: Infinity,
reportCompressedSize: false,
rollupOptions: {
external: Object.keys('dependencies' in pkg ? pkg.dependencies : {})
}
}
}
}
]),
renderer({ nodeIntegration: true })
],
resolve: {
alias: {
'@': __dirname
}
},
server: {
host: '0.0.0.0',
port: 5173
},
build: {
rollupOptions: {
external: [],
input: {
translate: resolve(__dirname, 'translate.html'),
takeword: resolve(__dirname, 'takeword.html')
}
}
},
clearScreen: false
}
})