-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
57 lines (48 loc) · 1.57 KB
/
vite.config.ts
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
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import url from 'node:url';
import {defineConfig} from 'vite';
// Vite Plugins
import preactPreset from '@preact/preset-vite';
import webExtension from 'vite-plugin-web-extension';
import createManifest from './source/manifest.js';
const targetBrowser = process.env.VITE_BROWSER ?? 'firefox';
process.env.VITE_BROWSER = targetBrowser;
const currentDir = path.dirname(url.fileURLToPath(import.meta.url));
const buildDir = path.join(currentDir, 'build', targetBrowser);
const sourceDir = path.join(currentDir, 'source');
// Create the browser profile if it doesn't already exist.
fs.mkdirSync(path.join(currentDir, targetBrowser), {recursive: true});
const webExtConfig: Record<string, unknown> = {
browserConsole: true,
chromiumProfile: 'chromium/',
firefoxProfile: 'firefox/',
keepProfileChanges: true,
};
if (targetBrowser === 'chromium') {
webExtConfig.startUrl = 'chrome://extensions/';
webExtConfig.target = 'chromium';
} else {
webExtConfig.startUrl = 'about:debugging#/runtime/this-firefox';
webExtConfig.target = 'firefox-desktop';
}
export default defineConfig({
build: {
outDir: buildDir,
minify: false,
sourcemap: 'inline',
},
plugins: [
preactPreset(),
// See vite-plugin-web-extension for documentation.
// https://github.com/aklinker1/vite-plugin-web-extension
webExtension({
assets: 'assets',
browser: targetBrowser,
manifest: () => createManifest(targetBrowser),
webExtConfig,
}),
],
root: sourceDir,
});