forked from imsyy/SPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelectron.vite.config.ts
More file actions
131 lines (129 loc) · 3.51 KB
/
electron.vite.config.ts
File metadata and controls
131 lines (129 loc) · 3.51 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import vue from "@vitejs/plugin-vue";
import { defineConfig, loadEnv } from "electron-vite";
import { resolve } from "path";
import AutoImport from "unplugin-auto-import/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
import Components from "unplugin-vue-components/vite";
import viteCompression from "vite-plugin-compression";
import type { MainEnv } from "./env";
// import VueDevTools from "vite-plugin-vue-devtools";
import wasm from "vite-plugin-wasm";
const commonResolve = {
alias: {
"@": resolve(__dirname, "src/"),
"@emi": resolve(__dirname, "native/external-media-integration"),
"@shared": resolve(__dirname, "src/types/shared"),
"@opencc": resolve(__dirname, "native/ferrous-opencc-wasm/pkg"),
"@native": resolve(__dirname, "native"),
},
};
export default defineConfig(({ mode }) => {
// 读取环境变量
const getEnv = (name: keyof MainEnv): string => {
return loadEnv(mode, process.cwd())[name];
};
// 获取端口
const webPort: number = Number(getEnv("VITE_WEB_PORT") || 14558);
const servePort: number = Number(getEnv("VITE_SERVER_PORT") || 25884);
// 返回配置
return {
// 主进程
main: {
build: {
publicDir: resolve(__dirname, "public"),
rollupOptions: {
input: {
index: resolve(__dirname, "electron/main/index.ts"),
"workers/audio-analysis.worker": resolve(
__dirname,
"electron/main/workers/audio-analysis.worker.ts",
),
},
},
},
resolve: commonResolve,
},
// 预加载
preload: {
build: {
rollupOptions: {
input: {
index: resolve(__dirname, "electron/preload/index.ts"),
},
},
},
resolve: commonResolve,
},
// 渲染进程
renderer: {
root: ".",
plugins: [
vue(),
// mode === "development" && VueDevTools(),
AutoImport({
imports: [
"vue",
"vue-router",
"@vueuse/core",
{
"naive-ui": ["useDialog", "useMessage", "useNotification", "useLoadingBar"],
},
],
eslintrc: {
enabled: true,
filepath: "./auto-eslint.mjs",
},
}),
Components({
resolvers: [NaiveUiResolver()],
}),
viteCompression(),
wasm(),
],
resolve: commonResolve,
css: {
preprocessorOptions: {
scss: {
silenceDeprecations: ["legacy-js-api"],
},
},
},
server: {
port: webPort,
// 代理
proxy: {
"/api": {
target: `http://127.0.0.1:${servePort}`,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, "/api"),
},
},
},
preview: {
port: webPort,
},
build: {
minify: "terser",
publicDir: resolve(__dirname, "public"),
rollupOptions: {
input: {
index: resolve(__dirname, "index.html"),
loading: resolve(__dirname, "web/loading/index.html"),
},
external: ["external-media-integration.node"],
output: {
manualChunks: {
stores: ["src/stores/data.ts", "src/stores/index.ts"],
},
},
},
terserOptions: {
compress: {
pure_funcs: ["console.log"],
},
},
sourcemap: false,
},
},
};
});