forked from MadhushaPrasad/accessible-theme-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
48 lines (45 loc) · 1.51 KB
/
Copy pathvite.config.js
File metadata and controls
48 lines (45 loc) · 1.51 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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import UnoCSS from 'unocss/vite'
import { resolve } from 'path'
import fs from 'fs'
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
// Detect target browser from environment variable, default to chrome
const targetBrowser = process.env.VITE_BROWSER || 'chrome'
return {
plugins: [
vue(),
UnoCSS(),
{
name: 'copy-extension-files',
// This hook runs after the entire build is finished
closeBundle: async () => {
const extensionSrc = resolve(__dirname, `src/extension/${targetBrowser}`)
const outDir = resolve(__dirname, 'dist')
if (fs.existsSync(extensionSrc)) {
try {
// Copy manifest, devtools, from src/extension/[browser] to dist/
// ensures folders like /popup and /images are copied too
fs.cpSync(extensionSrc, outDir, { recursive: true })
console.log(`✅ ${targetBrowser.toUpperCase()} extension files moved to dist root.`)
} catch (err) {
console.error(`❌ Error copying ${targetBrowser} files:`, err)
}
} else {
console.warn(`⚠️ Source folder not found: ${extensionSrc}`)
}
},
},
],
build: {
outDir: 'dist',
emptyOutDir: true, // Clears dist before each build
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
},
},
},
}
})