-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
85 lines (81 loc) · 1.86 KB
/
vite.config.ts
File metadata and controls
85 lines (81 loc) · 1.86 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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vite-plugin-electron'
import path from 'node:path'
import fs from 'node:fs'
// 自定义插件:直接复制 preload 文件
const copyPreloadPlugin = () => ({
name: 'copy-preload',
writeBundle() {
const src = 'electron/preload/index.js'
const dest = 'dist-electron/preload/index.cjs'
const dir = path.dirname(dest)
// 确保目录存在
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true })
}
// 直接复制文件
fs.copyFileSync(src, dest)
console.log('✓ Preload script copied directly')
}
})
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
electron([
{
// 主进程入口
entry: 'electron/main/index.ts',
vite: {
build: {
outDir: 'dist-electron/main',
rollupOptions: {
external: ['electron'],
output: {
entryFileNames: 'index.mjs'
}
}
}
}
},
{
// 预加载脚本 - 使用自定义插件处理
entry: 'electron/preload/index.js',
onstart(options) {
options.reload()
},
vite: {
plugins: [copyPreloadPlugin()],
build: {
outDir: 'dist-electron/preload',
rollupOptions: {
external: ['electron'],
output: {
entryFileNames: 'index.cjs'
}
}
}
}
}
])
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src')
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "@/assets/styles/variables.scss" as *;`
}
}
},
build: {
outDir: 'dist'
},
server: {
port: 5173
}
})