-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.config.chrome.ts
More file actions
52 lines (48 loc) · 1.41 KB
/
vite.config.chrome.ts
File metadata and controls
52 lines (48 loc) · 1.41 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
import { readFile, writeFile } from 'node:fs/promises';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import preact from '@preact/preset-vite';
import tailwindcss from '@tailwindcss/vite';
import { defineConfig } from 'vite';
const __dirname = dirname(fileURLToPath(import.meta.url));
function copyManifestPlugin() {
return {
name: 'copy-manifest',
async writeBundle() {
const srcPath = resolve(__dirname, 'src/manifest.chrome.json');
const destPath = resolve('dist/chrome/manifest.json');
try {
const content = await readFile(srcPath, 'utf8');
await writeFile(destPath, content);
console.log('dist/chrome/manifest.json');
} catch (err) {
console.error('Failed to copy manifest:', err);
}
},
};
}
// https://vite.dev/config/
export default defineConfig({
plugins: [preact(), tailwindcss(), copyManifestPlugin()],
build: {
outDir: 'dist/chrome',
emptyOutDir: true,
rollupOptions: {
input: {
popup: resolve(__dirname, 'src/popup/popup.html'),
ServiceWorker: resolve(__dirname, 'src/ServiceWorker.ts'),
Content: resolve(__dirname, 'src/Content.ts'),
},
output: {
assetFileNames: assetInfo => {
if (assetInfo.names[0].endsWith('.css')) {
return 'assets/output.css';
}
return 'assets/[name].[hash][extname]';
},
entryFileNames: '[name].js',
chunkFileNames: 'chunks/[name].js',
},
},
},
});