-
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathvite.firefox.config.ts
More file actions
93 lines (80 loc) · 3.07 KB
/
vite.firefox.config.ts
File metadata and controls
93 lines (80 loc) · 3.07 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
import { defineConfig, mergeConfig } from 'vite';
import baseConfig from './vite.config';
import { copyFileSync, mkdirSync, existsSync, cpSync, rmSync } from 'fs';
// Custom plugin to copy Firefox-specific assets
function copyFirefoxAssetsPlugin() {
return {
name: 'copy-firefox-assets',
writeBundle() {
const outDir = 'dist/firefox';
// Copy Firefox manifest
copyFileSync('src/manifest-ff.json', `${outDir}/manifest.json`);
// Copy icons directory
if (existsSync('src/icons')) {
cpSync('src/icons', `${outDir}/icons`, { recursive: true });
}
// Copy view icons
if (existsSync('src/views/icons')) {
if (!existsSync(`${outDir}/views/icons`)) {
mkdirSync(`${outDir}/views/icons`, { recursive: true });
}
cpSync('src/views/icons', `${outDir}/views/icons`, { recursive: true });
}
// Copy fonts
if (existsSync('src/views/fonts')) {
if (!existsSync(`${outDir}/views/fonts`)) {
mkdirSync(`${outDir}/views/fonts`, { recursive: true });
}
cpSync('src/views/fonts', `${outDir}/views/fonts`, { recursive: true });
}
// Copy settings icons
if (existsSync('src/views/settings/icons')) {
if (!existsSync(`${outDir}/views/settings/icons`)) {
mkdirSync(`${outDir}/views/settings/icons`, { recursive: true });
}
cpSync('src/views/settings/icons', `${outDir}/views/settings/icons`, { recursive: true });
}
// Copy locales directory
if (existsSync('src/_locales')) {
cpSync('src/_locales', `${outDir}/_locales`, { recursive: true });
}
// Copy HTML files to correct locations
if (existsSync(`${outDir}/src/views/popup.html`)) {
if (!existsSync(`${outDir}/views`)) {
mkdirSync(`${outDir}/views`, { recursive: true });
}
copyFileSync(`${outDir}/src/views/popup.html`, `${outDir}/views/popup.html`);
}
if (existsSync(`${outDir}/src/views/settings/settings.html`)) {
if (!existsSync(`${outDir}/views/settings`)) {
mkdirSync(`${outDir}/views/settings`, { recursive: true });
}
copyFileSync(`${outDir}/src/views/settings/settings.html`, `${outDir}/views/settings/settings.html`);
}
if (existsSync(`${outDir}/src/views/background.html`)) {
if (!existsSync(`${outDir}/views`)) {
mkdirSync(`${outDir}/views`, { recursive: true });
}
copyFileSync(`${outDir}/src/views/background.html`, `${outDir}/views/background.html`);
}
if (existsSync(`${outDir}/src`)) {
rmSync(`${outDir}/src`, { recursive: true, force: true });
}
console.log('Firefox assets copied successfully');
}
};
}
export default defineConfig(
mergeConfig(baseConfig, {
plugins: [copyFirefoxAssetsPlugin()],
define: {
'process.env.BROWSER': JSON.stringify('firefox'),
'process.env.NODE_ENV': JSON.stringify('production')
},
build: {
outDir: 'dist/firefox',
sourcemap: false,
minify: true
}
})
);