-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
76 lines (70 loc) · 2.59 KB
/
Copy pathvite.config.ts
File metadata and controls
76 lines (70 loc) · 2.59 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
import { defineConfig } from 'vite';
import { resolve } from 'path';
import { copyFileSync, existsSync, mkdirSync } from 'fs';
export default defineConfig({
build: {
outDir: 'dist',
rollupOptions: {
input: {
'background/service-worker': resolve(__dirname, 'src/background/service-worker.ts'),
'content/content-script': resolve(__dirname, 'src/content/content-script.ts'),
'content/world-script': resolve(__dirname, 'src/content/world-script.ts'),
'popup/popup': resolve(__dirname, 'src/popup/popup.ts'),
'options/options': resolve(__dirname, 'src/options/options.ts'),
},
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]',
},
},
minify: true,
sourcemap: true,
target: 'es2020',
},
plugins: [
{
name: 'copy-manifest',
writeBundle() {
// Copy manifest.json to dist directory
const manifestSrc = resolve(__dirname, 'manifest.json');
const manifestDest = resolve(__dirname, 'dist/manifest.json');
if (existsSync(manifestSrc)) {
copyFileSync(manifestSrc, manifestDest);
console.log('✓ Copied manifest.json to dist/');
}
// Also copy popup, options, and icons files
const filesToCopy = [
{ src: 'popup/popup.html', dest: 'dist/popup/popup.html' },
{ src: 'popup/popup.css', dest: 'dist/popup/popup.css' },
{ src: 'options/options.html', dest: 'dist/options/options.html' },
{ src: 'options/options.css', dest: 'dist/options/options.css' },
{ src: 'icons/icon-16.png', dest: 'dist/icons/icon-16.png' },
{ src: 'icons/icon-32.png', dest: 'dist/icons/icon-32.png' },
{ src: 'icons/icon-48.png', dest: 'dist/icons/icon-48.png' },
{ src: 'icons/icon-128.png', dest: 'dist/icons/icon-128.png' },
];
filesToCopy.forEach(({ src, dest }) => {
const srcPath = resolve(__dirname, src);
const destPath = resolve(__dirname, dest);
const destDir = resolve(__dirname, dest.split('/').slice(0, -1).join('/'));
if (!existsSync(destDir)) {
mkdirSync(destDir, { recursive: true });
}
if (existsSync(srcPath)) {
copyFileSync(srcPath, destPath);
console.log(`✓ Copied ${src} to ${dest}`);
}
});
},
},
],
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
},
});