Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
78 lines (73 loc) · 2.03 KB
/
Copy pathvite.config.js
File metadata and controls
78 lines (73 loc) · 2.03 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
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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
// Configures multi-build outputs for extension components (popup, background, content script)
const isPopupBuild = process.env.BUILD_TARGET === 'popup';
const isBgBuild = process.env.BUILD_TARGET === 'background';
function getConfig() {
if (isPopupBuild) {
return defineConfig({
plugins: [react()],
root: resolve(__dirname, 'src/popup'),
base: './',
build: {
outDir: resolve(__dirname, 'dist'),
emptyOutDir: false,
rollupOptions: {
input: resolve(__dirname, 'src/popup/popup.html'),
output: {
entryFileNames: 'popup.js',
assetFileNames: 'popup-[name][extname]',
},
},
minify: false,
target: 'esnext',
},
});
}
if (isBgBuild) {
return defineConfig({
build: {
outDir: 'dist',
emptyOutDir: false,
lib: {
entry: resolve(__dirname, 'src/background/service-worker.js'),
name: 'background',
fileName: () => 'background.js',
formats: ['es'],
},
minify: false,
target: 'esnext',
},
});
}
// Default: content script build (IIFE, single bundle)
return defineConfig({
plugins: [react()],
build: {
outDir: 'dist',
emptyOutDir: true,
rollupOptions: {
input: resolve(__dirname, 'src/content/content-main.jsx'),
output: {
entryFileNames: 'content-bundle.js',
assetFileNames: (assetInfo) => {
if (assetInfo.name && assetInfo.name.endsWith('.css')) {
return 'content-bundle.css';
}
return 'assets/[name]-[hash][extname]';
},
format: 'iife',
inlineDynamicImports: true,
},
},
cssCodeSplit: false,
target: 'esnext',
minify: false,
},
resolve: {
alias: { '@': resolve(__dirname, 'src') },
},
});
}
export default getConfig();