-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
vite.config.ts
86 lines (80 loc) · 2 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
83
84
85
86
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import Icons from 'unplugin-icons/vite';
import { defineConfig } from 'vitest/config';
import { EVENT_CONTENT, EVENT_MAIN } from './src/common/constants';
const defaultConfig = defineConfig({
plugins: [vue(), Icons({ compiler: 'vue3' })],
build: {
target: 'chrome99',
modulePreload: false,
minify: process.env.NODE_ENV !== 'development',
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
});
const configBackground = defineConfig({
...defaultConfig,
// Set root to correct the output paths of HTMLs
root: 'src',
build: {
...defaultConfig.build,
emptyOutDir: false,
outDir: '../dist',
rollupOptions: {
input: {
handler: resolve(__dirname, 'src/handler/index.ts'),
options: resolve(__dirname, 'src/options/index.html'),
popup: resolve(__dirname, 'src/popup/index.html'),
},
output: {
entryFileNames: '[name]/index.js',
},
},
},
});
const configContent = defineConfig({
...defaultConfig,
// Set root to correct the output paths of HTMLs
root: 'src',
build: {
...defaultConfig.build,
emptyOutDir: false,
outDir: '../dist',
rollupOptions: {
input: {
content: resolve(__dirname, 'src/content/index.ts'),
},
output: {
entryFileNames: '[name]/index.js',
format: 'iife',
},
},
},
});
const configConnector = defineConfig({
...defaultConfig,
define: {
__INJECT__EVENT_MAIN: JSON.stringify(EVENT_MAIN),
__INJECT__EVENT_CONTENT: JSON.stringify(EVENT_CONTENT),
},
build: {
...defaultConfig.build,
outDir: 'lib',
lib: {
entry: resolve(__dirname, 'src/connector/index.ts'),
fileName: 'index',
formats: ['es'],
},
},
});
const configMap = {
background: configBackground,
content: configContent,
connector: configConnector,
};
const config = configMap[process.env.ENTRY || ''] || configMap.background;
export default config;