-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectron.vite.config.ts
More file actions
83 lines (73 loc) · 2.53 KB
/
electron.vite.config.ts
File metadata and controls
83 lines (73 loc) · 2.53 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
/*
* @Author: Night-stars-1 nujj1042633805@gmail.com
* @Date: 2024-09-06 17:06:15
* @LastEditors: Night-stars-1 nujj1042633805@gmail.com
* @LastEditTime: 2024-12-23 12:38:20
*/
import path, { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import vuetify from 'vite-plugin-vuetify'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
function setVersion() {
const packageJson = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8'))
const appVersion = packageJson.version
const envPath = resolve(__dirname, '.env')
let envContent = readFileSync(envPath, 'utf-8')
const versionLine = `VITE_VERSION=${appVersion}\n`
envContent = envContent.replace(/VITE_VERSION=.*/g, versionLine.trim())
writeFileSync(envPath, envContent, 'utf-8')
}
function configureOcrModel() {
const ocrAssetsDir = path.join('resources', 'MaaCommonAssets', 'OCR')
// 如果没有找到 MaaCommonAssets/OCR 目录
if (!existsSync(ocrAssetsDir)) {
console.log('请完整克隆本仓库,不要漏掉 "--recursive",也不要下载 zip 包!')
console.log('你可以使用 git submodule update --init --recursive 克隆子模块')
process.exit(1) // 退出程序
}
const ocrDir = path.join(__dirname, 'resources', 'model', 'ocr')
// 仅当 OCR 目录不存在时,复制默认的 OCR 模型
if (!existsSync(ocrDir)) {
mkdirSync(ocrDir, { recursive: true })
cpSync(
path.join(ocrAssetsDir, 'ppocr_v4', 'zh_cn'),
ocrDir,
{ recursive: true, force: true } // recursive 确保递归复制,force 覆盖现有文件
)
} else {
console.log('找到现有OCR目录,跳过默认OCR模型导入')
}
}
setVersion()
configureOcrModel()
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()]
},
preload: {
plugins: [externalizeDepsPlugin()]
},
renderer: {
resolve: {
alias: {
'@renderer': resolve('src/renderer/src'),
'@stores': resolve('src/renderer/src/plugins/pinia')
}
},
plugins: [
vue(),
vuetify({ autoImport: true }),
AutoImport({
imports: ['vue', 'vue-router', 'pinia'],
dts: resolve('src/renderer/src/types/auto-imports.d.ts')
}),
Components({
dirs: [resolve('src/renderer/src/components')],
dts: resolve('src/renderer/src/types/components.d.ts')
})
]
}
})