-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
85 lines (81 loc) · 2.19 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import fs from 'fs'
export default defineConfig({
plugins: [
react(),
{
name: 'hot-reload',
configureServer(server) {
// 监听文件变化
server.watcher.on('change', (file) => {
// 如果是 manifest.json 或 background script 发生变化
if (file.includes('manifest.json') || file.includes('background.ts')) {
console.log('Detected changes in core files, triggering extension reload...');
// 这里可以添加扩展重载逻辑
}
});
}
},
{
name: 'copy-manifest',
closeBundle() {
// 确保目标目录存在
if (!fs.existsSync('dist')) {
fs.mkdirSync('dist', { recursive: true });
}
// 复制manifest.json
if (fs.existsSync('manifest.json')) {
fs.copyFileSync('manifest.json', 'dist/manifest.json');
console.log('Manifest file copied successfully');
}
// 复制图标目录
if (fs.existsSync('icons')) {
if (!fs.existsSync('dist/icons')) {
fs.mkdirSync('dist/icons', { recursive: true });
}
const icons = fs.readdirSync('icons');
icons.forEach(icon => {
fs.copyFileSync(`icons/${icon}`, `dist/icons/${icon}`);
});
console.log('Icons copied successfully');
}
}
}
],
server: {
port: 3000,
hmr: {
protocol: 'ws',
host: 'localhost',
overlay: true
},
watch: {
ignored: ['!**/node_modules/**']
}
},
build: {
rollupOptions: {
input: {
popup: resolve(__dirname, 'index.html'),
background: resolve(__dirname, 'src/background.ts')
},
output: {
entryFileNames: chunk => {
return chunk.name === 'background' ? 'src/[name].js' : '[name].js';
},
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]'
}
},
outDir: 'dist',
sourcemap: false,
minify: false
},
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
}
})