forked from imsyy/SPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelectron.vite.config.mjs
160 lines (159 loc) · 4.37 KB
/
electron.vite.config.mjs
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import { resolve } from "path";
import { defineConfig, externalizeDepsPlugin, loadEnv } from "electron-vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
import { VitePWA } from "vite-plugin-pwa";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import viteCompression from "vite-plugin-compression";
import checkPort from "./electron/main/utils/checkPort";
export default defineConfig(async ({ mode }) => {
// 读取环境变量
const getEnv = (name) => {
return loadEnv(mode, process.cwd())[name];
};
// 获取端口
const devPort = await checkPort(getEnv("MAIN_VITE_DEV_PORT"));
const serverPort = await checkPort(getEnv("MAIN_VITE_SERVER_PORT"));
// 返回配置
return {
// 主进程
main: {
resolve: {
alias: {
"@main": resolve(__dirname, "electron/main"),
},
},
plugins: [externalizeDepsPlugin()],
build: {
publicDir: resolve(__dirname, "public"),
rollupOptions: {
input: {
index: resolve(__dirname, "electron/main/index.js"),
},
},
},
},
// 预渲染
preload: {
plugins: [externalizeDepsPlugin()],
build: {
rollupOptions: {
input: {
index: resolve(__dirname, "electron/preload/index.mjs"),
},
},
},
},
// 渲染进程
renderer: {
resolve: {
extensions: [".js", ".vue", ".json"],
alias: {
"@": resolve(__dirname, "src"),
},
},
plugins: [
vue(),
AutoImport({
imports: [
"vue",
{
"naive-ui": ["useDialog", "useMessage", "useNotification", "useLoadingBar"],
},
],
}),
Components({
resolvers: [NaiveUiResolver()],
}),
// viteCompression
viteCompression(),
// PWA
VitePWA({
registerType: "autoUpdate",
workbox: {
clientsClaim: true,
skipWaiting: true,
cleanupOutdatedCaches: true,
runtimeCaching: [
{
urlPattern: /(.*?)\.(woff2|woff|ttf)/,
handler: "CacheFirst",
options: {
cacheName: "file-cache",
},
},
{
urlPattern: /(.*?)\.(webp|png|jpe?g|svg|gif|bmp|psd|tiff|tga|eps)/,
handler: "CacheFirst",
options: {
cacheName: "image-cache",
},
},
],
},
manifest: {
name: getEnv("RENDERER_VITE_SITE_TITLE"),
short_name: getEnv("RENDERER_VITE_SITE_TITLE"),
description: getEnv("RENDERER_VITE_SITE_DES"),
display: "standalone",
start_url: "/",
theme_color: "#fff",
background_color: "#efefef",
icons: [
{
src: "/imgs/icons/favicon-32x32.png",
sizes: "32x32",
type: "image/png",
},
{
src: "/imgs/icons/favicon-96x96.png",
sizes: "96x96",
type: "image/png",
},
{
src: "/imgs/icons/favicon-256x256.png",
sizes: "256x256",
type: "image/png",
},
{
src: "/imgs/icons/favicon-512x512.png",
sizes: "512x512",
type: "image/png",
},
],
},
}),
],
// 服务器配置
server: {
port: devPort,
// 代理
proxy: {
"/api": {
target: `http://${getEnv("MAIN_VITE_SERVER_HOST")}:${serverPort}`,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
},
// 构建
root: ".",
build: {
minify: "terser",
publicDir: resolve(__dirname, "public"),
rollupOptions: {
input: {
index: resolve(__dirname, "index.html"),
},
},
terserOptions: {
compress: {
pure_funcs: ["console.log"],
},
},
sourcemap: false,
},
},
};
});