-
Notifications
You must be signed in to change notification settings - Fork 696
/
electron.vite.config.ts
155 lines (152 loc) · 5.03 KB
/
electron.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
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
import { resolve } from 'path';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { defineConfig, externalizeDepsPlugin, swcPlugin } from 'electron-vite';
import { ConfigEnv, loadEnv } from 'vite';
import vueDevTools from 'vite-plugin-vue-devtools';
import svgLoader from 'vite-svg-loader';
// 按需加载T-Desgin组件
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { TDesignResolver } from 'unplugin-vue-components/resolvers';
const CWD = process.cwd();
// see config at https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv) => {
const { VITE_API_URL, VITE_API_URL_PREFIX } = loadEnv(mode, CWD);
return {
main: {
resolve: {
alias: {
'@main': resolve('src/main'),
},
},
build: {
sourcemap: false,
rollupOptions: {
onwarn: (warning, warn) => {
if (warning.code === 'EVAL') return; // 忽略 eval 警告
if (warning.code === 'SOURCEMAP_ERROR') return; // 忽略 sourcemap 错误
warn(warning);
},
input: {
index: resolve(__dirname, 'src/main/index.ts'),
worker: resolve(__dirname, 'src/main/core/server/routes/v1/site/cms/adapter/drpy/worker.ts'),
},
output: {
manualChunks: {
fastify: ['fastify', 'fastify-logger', 'fastify-plugin', '@fastify/cors', '@fastify/multipart'],
db: ['drizzle-kit', 'drizzle-orm'],
crypto: ['crypto-js', 'he', 'pako', 'wxmp-rsa'],
},
},
external: [],
},
},
plugins: [externalizeDepsPlugin(), swcPlugin()],
},
preload: {
plugins: [externalizeDepsPlugin()],
},
renderer: {
resolve: {
alias: {
'@renderer': resolve('src/renderer'),
'@': resolve('src/renderer/src'),
},
},
build: {
emptyOutDir: true, // 打包时先清空上一次构建生成的目录
sourcemap: false, // 关闭生成map文件 可以达到缩小打包体积
minify: false, // 关闭压缩
chunkSizeWarningLimit: 2000, // 打包后超过2kb的会单独打包
assetsInlineLimit: 4096, // 小于4kb的图片会转成base64
rollupOptions: {
output: {
entryFileNames: `assets/entry/[name][hash].js`, // 引入文件名的名称
chunkFileNames: `assets/chunk/[name][hash].js`, // 包的入口文件名称
assetFileNames: `assets/static/[ext]/[name][hash].[ext]`, // 资源文件像 字体,图片等
manualChunks: {
'monaco-editor': ['monaco-editor'],
lodash: ['lodash'],
xgplayer: [
'xgplayer',
'xgplayer-dash',
'xgplayer-flv',
'xgplayer-flv.js',
'xgplayer-hls',
'xgplayer-hls.js',
'xgplayer-mp4',
'xgplayer-shaka',
],
artplayer: ['artplayer', 'artplayer-plugin-danmuku'],
dplayer: ['dplayer'],
nplayer: ['nplayer', '@nplayer/danmaku'],
videoDecoder: ['flv.js', 'hls.js', 'shaka-player', 'mpegts.js'],
tdesign: ['tdesign-vue-next', 'tdesign-icons-vue-next'],
md: ['github-markdown-css', 'markdown-it', 'markdown-it-highlightjs', 'markdown-it-mathjax3'],
crypto: ['crypto-js', 'he', 'pako', 'wxmp-rsa'],
vue: [
'vue',
'vue-router',
'pinia',
'vue-i18n',
'pinia-plugin-persistedstate',
'qrcode.vue',
'smooth-scrollbar',
'v3-infinite-loading',
'mitt',
'@imengyu/vue3-context-menu',
],
},
},
},
},
css: {
preprocessorOptions: {
less: {
modifyVars: {
hack: `true; @import (reference) "${resolve('src/renderer/src/style/variables.less')}";`,
},
math: 'strict',
javascriptEnabled: true,
},
},
},
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag === 'webview' || tag === 'title-bar',
},
},
}),
vueJsx(),
vueDevTools(),
svgLoader(),
AutoImport({
resolvers: [
TDesignResolver({
library: 'vue-next',
}),
],
}),
Components({
resolvers: [
TDesignResolver({
library: 'vue-next',
}),
],
}),
],
server: {
strictPort: true, // 端口冲突自动分配端口
proxy: {
[VITE_API_URL_PREFIX]: {
target: VITE_API_URL, // 后台接口域名
changeOrigin: true, //是否跨域
},
},
},
},
};
});