-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathvite.main.ts
More file actions
46 lines (44 loc) · 1.3 KB
/
Copy pathvite.main.ts
File metadata and controls
46 lines (44 loc) · 1.3 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
import { defineConfig, UserConfig } from 'vite'
import { resolve } from 'path'
import { builtinModules } from 'node:module'
import fs from 'fs-extra'
import path from 'path'
import keys from 'licia/keys'
import { alias } from './vite.config'
const pkg = fs.readJSONSync(path.resolve(__dirname, 'package.json'))
const external = builtinModules.filter((e) => !e.startsWith('_'))
external.push(
'electron',
...keys(pkg.optionalDependencies || {}),
...keys(pkg.dependencies || {}),
...external.map((m) => `node:${m}`)
)
export default defineConfig(async ({ mode }): Promise<UserConfig> => {
const pkg = await fs.readJSON(path.resolve(__dirname, 'package.json'))
return {
build: {
outDir: 'dist/main',
minify: mode === 'development' ? false : 'esbuild',
lib: {
entry: {
index: resolve(__dirname, 'src/main/index.ts'),
cli: resolve(__dirname, 'src/main/cli/index.ts'),
},
name: 'Main',
formats: ['cjs'],
},
rollupOptions: {
external: (id) =>
external.some((pkg) => id === pkg || id.startsWith(pkg + '/')),
},
},
resolve: {
mainFields: ['main', 'module'],
alias,
},
define: {
PRODUCT_NAME: JSON.stringify(pkg.productName),
VERSION: JSON.stringify(pkg.version),
},
}
})