-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
111 lines (97 loc) · 3.34 KB
/
vite.config.js
File metadata and controls
111 lines (97 loc) · 3.34 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import fs from 'fs';
import path from 'path';
// 自定义插件,用于复制资源文件到dist目录
const copyAssetsPlugin = () => {
return {
name: 'copy-assets',
closeBundle() {
// 确保目标目录存在
const ensureDir = (dir) => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
};
// 复制文件
const copyFile = (src, dest) => {
try {
fs.copyFileSync(src, dest);
console.log(`Copied: ${src} -> ${dest}`);
} catch (err) {
console.error(`Error copying ${src} to ${dest}:`, err);
}
};
// 复制目录
const copyDir = (src, dest) => {
ensureDir(dest);
const files = fs.readdirSync(src);
files.forEach(file => {
const srcPath = path.join(src, file);
const destPath = path.join(dest, file);
if (fs.statSync(srcPath).isDirectory()) {
copyDir(srcPath, destPath);
} else {
copyFile(srcPath, destPath);
}
});
};
// 创建目录
ensureDir('dist/icons');
ensureDir('dist/popup');
ensureDir('dist/tests');
ensureDir('dist/js/tests');
ensureDir('dist/libs');
// 复制图标
copyFile('src/icons/icon16.png', 'dist/icons/icon16.png');
copyFile('src/icons/icon48.png', 'dist/icons/icon48.png');
copyFile('src/icons/icon128.png', 'dist/icons/icon128.png');
// 复制JSZip库
copyFile('src/libs/jszip.min.js', 'dist/libs/jszip.min.js');
// 复制HTML文件
copyFile('src/popup/index.html', 'dist/popup/index.html');
copyFile('src/popup/export.html', 'dist/popup/export.html');
// 复制CSS文件
copyFile('src/popup/styles.css', 'dist/popup/styles.css');
// 复制测试文件
ensureDir('dist/tests');
copyFile('src/tests/tests.html', 'dist/tests/tests.html');
copyFile('src/tests/e2e.html', 'dist/tests/e2e.html');
copyFile('src/tests/compatibility.html', 'dist/tests/compatibility.html');
// 直接复制测试JS文件而非通过打包
copyFile('src/tests/functionality.test.js', 'dist/tests/functionality.test.js');
copyFile('src/tests/e2e.test.js', 'dist/tests/e2e.test.js');
copyFile('src/tests/compatibility.test.js', 'dist/tests/compatibility.test.js');
// 复制manifest.json
copyFile('src/manifest.json', 'dist/manifest.json');
}
};
};
export default defineConfig({
plugins: [react(), copyAssetsPlugin()],
build: {
outDir: 'dist',
emptyOutDir: true,
rollupOptions: {
input: {
background: resolve(__dirname, 'src/background.js'),
content: resolve(__dirname, 'src/content/main.js'),
deepseek: resolve(__dirname, 'src/content/deepseek.js'),
doubao: resolve(__dirname, 'src/content/doubao.js'),
popup: resolve(__dirname, 'src/popup/popup.js'),
export: resolve(__dirname, 'src/popup/export.js')
},
output: {
entryFileNames: 'js/[name].js',
chunkFileNames: 'js/[name].js',
assetFileNames: 'assets/[name].[ext]'
}
}
},
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
}
});