forked from Hiram-Wong/ZyPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelectron.vite.config.ts
110 lines (107 loc) · 3.16 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
import { resolve } from 'path';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { defineConfig, externalizeDepsPlugin, swcPlugin, splitVendorChunkPlugin } from 'electron-vite';
import { ConfigEnv, loadEnv } from 'vite';
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: {
rollupOptions: {
external: ['sqlite3']
}
},
plugins: [
externalizeDepsPlugin(),
swcPlugin()
]
},
preload: {
plugins: [externalizeDepsPlugin()]
},
renderer: {
resolve: {
alias: {
'@renderer': resolve('src/renderer'),
'@': resolve('src/renderer/src')
}
},
build: {
emptyOutDir: true, // 打包时先清空上一次构建生成的目录
reportCompressedSize: false, // 关闭文件计算
sourcemap: false, // 关闭生成map文件 可以达到缩小打包体积
rollupOptions: {
output: {
entryFileNames: `assets/entry/[name][hash].js`, // 引入文件名的名称
chunkFileNames: `assets/chunk/[name][hash].js`, // 包的入口文件名称
assetFileNames: `assets/file/[name][hash].[ext]`, // 资源文件像 字体,图片等
manualChunks(id) {
console.log(id)
if (id.includes("node_modules")) return "vendor_"; //代码分割为第三方包
if (id.includes("src/renderer/src/utils/drpy")) return "worker_t3_"; //代码分割为worker进程
}
}
}
},
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',
},
},
}),
vueJsx(),
svgLoader(),
AutoImport({
resolvers: [
TDesignResolver({
library: 'vue-next',
}),
],
}),
Components({
resolvers: [
TDesignResolver({
library: 'vue-next',
}),
],
}),
splitVendorChunkPlugin()
],
server: {
strictPort: true, // 端口冲突自动分配端口
proxy: {
[VITE_API_URL_PREFIX]: {
target: VITE_API_URL, // 后台接口域名
changeOrigin: true, //是否跨域
}
}
}
}
}
})