-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
90 lines (85 loc) · 2.8 KB
/
vite.config.ts
File metadata and controls
90 lines (85 loc) · 2.8 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
79
80
81
82
83
84
85
86
87
88
89
90
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';
import { resolve } from 'path';
import { readFileSync, writeFileSync, copyFileSync, mkdirSync, readdirSync, statSync } from 'fs';
// Recursively copy a directory
function copyDirRecursive(src: string, dest: string) {
mkdirSync(dest, { recursive: true });
for (const entry of readdirSync(src)) {
const srcPath = resolve(src, entry);
const destPath = resolve(dest, entry);
if (statSync(srcPath).isDirectory()) {
copyDirRecursive(srcPath, destPath);
} else {
copyFileSync(srcPath, destPath);
}
}
}
// Plugin to copy and patch manifest + icons into dist
function copyExtensionFiles() {
return {
name: 'copy-extension-files',
writeBundle() {
// Copy and patch manifest.json — fix side_panel path
const manifest = JSON.parse(
readFileSync(resolve(__dirname, 'manifest.json'), 'utf-8')
);
manifest.side_panel.default_path = 'src/sidepanel/index.html';
writeFileSync(
resolve(__dirname, 'dist/manifest.json'),
JSON.stringify(manifest, null, 2)
);
// Copy icons
const iconsDir = resolve(__dirname, 'public/icons');
const distIconsDir = resolve(__dirname, 'dist/icons');
try {
mkdirSync(distIconsDir, { recursive: true });
for (const file of readdirSync(iconsDir)) {
if (file.endsWith('.png')) {
copyFileSync(resolve(iconsDir, file), resolve(distIconsDir, file));
}
}
} catch {
// Icons dir may not exist yet
}
// Copy _locales directory for i18n
const localesDir = resolve(__dirname, '_locales');
try {
copyDirRecursive(localesDir, resolve(__dirname, 'dist/_locales'));
} catch {
// _locales dir may not exist yet
}
},
};
}
export default defineConfig({
plugins: [react(), tailwindcss(), copyExtensionFiles()],
resolve: {
alias: {
'@shared': resolve(__dirname, 'src/shared'),
'@background': resolve(__dirname, 'src/background'),
'@sidepanel': resolve(__dirname, 'src/sidepanel'),
},
},
build: {
outDir: 'dist',
emptyOutDir: true,
rollupOptions: {
input: {
sidepanel: resolve(__dirname, 'src/sidepanel/index.html'),
background: resolve(__dirname, 'src/background/index.ts'),
content: resolve(__dirname, 'src/content/index.ts'),
},
output: {
entryFileNames: (chunkInfo) => {
if (chunkInfo.name === 'background') return 'background.js';
if (chunkInfo.name === 'content') return 'content.js';
return 'assets/[name]-[hash].js';
},
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash].[ext]',
},
},
},
});