-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
95 lines (89 loc) · 2.9 KB
/
vite.config.ts
File metadata and controls
95 lines (89 loc) · 2.9 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
91
92
93
94
95
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { copyFileSync, mkdirSync, existsSync } from 'fs';
// Plugin to copy static files (manifest.json and icons)
const copyStaticFiles = () => ({
name: 'copy-static-files',
closeBundle() {
const distDir = resolve(__dirname, 'dist');
const iconsDir = resolve(distDir, 'icons');
// Create icons directory if it doesn't exist
if (!existsSync(iconsDir)) {
mkdirSync(iconsDir, { recursive: true });
}
// Copy manifest.json
copyFileSync(
resolve(__dirname, 'manifest.json'),
resolve(distDir, 'manifest.json')
);
// Copy icons
const iconFiles = ['icon.svg', 'icon16.png', 'icon16.svg', 'icon48.png', 'icon48.svg', 'icon128.png', 'icon128.svg'];
iconFiles.forEach(file => {
const srcPath = resolve(__dirname, 'icons', file);
const destPath = resolve(iconsDir, file);
if (existsSync(srcPath)) {
copyFileSync(srcPath, destPath);
}
});
console.log('✓ Static files copied (manifest.json, icons)');
}
});
export default defineConfig({
plugins: [react(), copyStaticFiles()],
build: {
outDir: 'dist',
sourcemap: process.env.NODE_ENV !== 'production',
minify: 'esbuild',
target: 'es2020',
rollupOptions: {
input: {
popup: resolve(__dirname, 'popup.html'),
sidepanel: resolve(__dirname, 'sidepanel.html'),
'profile-renderer': resolve(__dirname, 'src/profile/profile-renderer.html'),
offscreen: resolve(__dirname, 'src/offscreen/offscreen.html'),
background: resolve(__dirname, 'src/background/background.ts'),
},
output: {
entryFileNames: (chunkInfo) => {
if (chunkInfo.name === 'background') {
return 'background.js';
}
if (chunkInfo.name === 'offscreen') {
return 'src/offscreen/offscreen.js';
}
return 'assets/[name]-[hash].js';
},
chunkFileNames: 'assets/[name]-[hash].js',
assetFileNames: 'assets/[name]-[hash].[ext]',
format: 'es',
manualChunks: (id) => {
if (id.includes('node_modules')) {
if (id.includes('react') || id.includes('react-dom')) {
return 'vendor-react';
}
if (id.includes('@synonymdev/pubky')) {
return 'vendor-pubky';
}
if (id.includes('pubky-app-specs')) {
return 'vendor-pubky-specs';
}
// Lazy load heavy dependencies
if (id.includes('qrcode')) {
return 'vendor-qrcode';
}
if (id.includes('react-image-crop')) {
return 'vendor-image-crop';
}
return 'vendor-other';
}
},
},
},
},
resolve: {
alias: {
'@': resolve(__dirname, './src'),
},
},
});