Skip to content

Commit 9875b77

Browse files
committed
chrome build system
1 parent 9a1b8f3 commit 9875b77

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
8-
"build": "vite build",
8+
"build": "npm run build:firefox",
9+
"build:firefox": "vite build && node scripts/build-manifest.js firefox",
10+
"build:chrome": "vite build && node scripts/build-manifest.js chrome",
911
"preview": "vite preview"
1012
},
1113
"devDependencies": {

scripts/build-manifest.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import fs from 'fs'
2+
import path from 'path'
3+
4+
const browser = process.argv[2] || 'firefox'
5+
const manifestPath = './public/manifest.json'
6+
const distPath = './dist'
7+
8+
// Read the source manifest
9+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'))
10+
11+
// Browser-specific modifications
12+
if (browser === 'chrome') {
13+
// Remove chrome_settings_overrides for Chrome due to search_provider bug
14+
delete manifest.chrome_settings_overrides
15+
// Remove Firefox-specific settings
16+
delete manifest.browser_specific_settings
17+
} else if (browser === 'firefox') {
18+
// Firefox manifest is already complete in the source
19+
// No modifications needed
20+
}
21+
22+
// Ensure dist directory exists
23+
if (!fs.existsSync(distPath)) {
24+
fs.mkdirSync(distPath, { recursive: true })
25+
}
26+
27+
// Write the browser-specific manifest
28+
fs.writeFileSync(
29+
path.join(distPath, 'manifest.json'),
30+
JSON.stringify(manifest, null, 4)
31+
)
32+
33+
console.log(`✓ Built manifest.json for ${browser}`)

vite.config.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,21 @@ function injectThemeScript() {
3131
}
3232
}
3333

34+
// Plugin to exclude manifest.json from public copy (we'll generate it separately)
35+
function excludeManifest() {
36+
return {
37+
name: 'exclude-manifest',
38+
generateBundle(options, bundle) {
39+
// Remove manifest.json from bundle if Vite copied it
40+
delete bundle['manifest.json']
41+
},
42+
}
43+
}
44+
3445
// https://vite.dev/config/
3546
export default defineConfig({
3647
base: './',
37-
plugins: [svelte(), injectThemeScript()],
48+
plugins: [svelte(), injectThemeScript(), excludeManifest()],
3849
define: {
3950
__APP_VERSION__: JSON.stringify(manifest.version),
4051
},

0 commit comments

Comments
 (0)