-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvite.config.ts
82 lines (80 loc) · 2.12 KB
/
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
import { fileURLToPath, URL } from 'node:url'
import * as path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vite-plugin-electron'
import electronRenderer from 'vite-plugin-electron/renderer'
import polyfillExports from 'vite-plugin-electron/polyfill-exports'
// import optimizer from 'vite-plugin-optimizer'
let getReplacer = () => {
let externalModels = ["electron", "os", "fs-extra", "path", "events", "child_process", "crypto", "http", "buffer", "url", "better-sqlite3", "knex"];
let result = {};
for (let item of externalModels) {
(result as any)[item] = () => ({
find: new RegExp(`^${item}$`),
code: `const ${item} = require('${item}');export { ${item} as default }`,
});
}
return result;
};
// https://vitejs.dev/config/
export default defineConfig({
base: "./",
plugins: [
// optimizer(getReplacer()),
vue(),
electron({
main:{
// 入口文件的路径
entry: "electron/main/main.ts",
vite: {
build: {
// 将入口文件转为 js 后输出到指定目录
outDir: "appDir/main"
}
}
},
preload: {
// 预加载文件的绝对路径
input: path.join(__dirname, "./electron/main/preload.ts"), // 预加载文件
vite: {
build: {
// 将预加载文件转为 js 后输出到指定目录
outDir: "appDir/preload"
}
}
}
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
}
},
css: {
preprocessorOptions: {
scss: {
javascriptEnabled: true,
additionalData: '@import "./src/styles/global.scss";',
},
},
},
build: {
emptyOutDir: true,
chunkSizeWarningLimit: 1000,
rollupOptions: {
output: {
// 分包
manualChunks(id) {
if (id.includes("node_modules")) {
return id
.toString()
.split("node_modules/")[1]
.split("/")[0]
.toString();
}
},
},
},
}
})