2022-03-05 13:10:45 +00:00
|
|
|
import fs from 'node:fs';
|
|
|
|
import path from 'node:path';
|
2022-03-20 18:02:37 +00:00
|
|
|
import process from 'node:process';
|
2022-03-05 13:10:45 +00:00
|
|
|
import url from 'node:url';
|
|
|
|
|
|
|
|
import {defineConfig} from 'vite';
|
|
|
|
|
|
|
|
// Vite Plugins
|
|
|
|
import preactPreset from '@preact/preset-vite';
|
|
|
|
import webExtension from 'vite-plugin-web-extension';
|
|
|
|
|
2022-03-24 13:56:42 +00:00
|
|
|
import createManifest from './source/manifest.js';
|
2022-03-20 20:52:53 +00:00
|
|
|
|
2022-03-20 18:02:37 +00:00
|
|
|
const targetBrowser = process.env.VITE_BROWSER ?? 'firefox';
|
|
|
|
process.env.VITE_BROWSER = targetBrowser;
|
|
|
|
|
2022-03-24 13:56:42 +00:00
|
|
|
const currentDir = path.dirname(url.fileURLToPath(import.meta.url));
|
|
|
|
const buildDir = path.join(currentDir, 'build', targetBrowser);
|
|
|
|
const sourceDir = path.join(currentDir, 'source');
|
|
|
|
|
|
|
|
fs.mkdirSync(path.join(currentDir, targetBrowser), {recursive: true});
|
|
|
|
|
|
|
|
const webExtConfig: Record<string, unknown> = {
|
|
|
|
browserConsole: true,
|
|
|
|
chromiumProfile: 'chromium/',
|
|
|
|
firefoxProfile: 'firefox/',
|
|
|
|
keepProfileChanges: true,
|
|
|
|
};
|
2022-03-20 18:02:37 +00:00
|
|
|
|
|
|
|
if (targetBrowser === 'chromium') {
|
2022-03-24 13:56:42 +00:00
|
|
|
webExtConfig.startUrl = 'chrome://extensions/';
|
|
|
|
webExtConfig.target = 'chromium';
|
2022-03-20 18:02:37 +00:00
|
|
|
} else {
|
2022-03-24 13:56:42 +00:00
|
|
|
webExtConfig.startUrl = 'about:debugging#/runtime/this-firefox';
|
|
|
|
webExtConfig.target = 'firefox-desktop';
|
2022-03-20 18:02:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-05 13:10:45 +00:00
|
|
|
export default defineConfig({
|
|
|
|
build: {
|
2022-03-24 09:22:32 +00:00
|
|
|
minify: false,
|
2022-03-05 13:10:45 +00:00
|
|
|
outDir: buildDir,
|
|
|
|
sourcemap: 'inline',
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
preactPreset(),
|
|
|
|
// See vite-plugin-web-extension for documentation.
|
|
|
|
// https://github.com/aklinker1/vite-plugin-web-extension
|
|
|
|
webExtension({
|
|
|
|
assets: 'assets',
|
2022-03-20 18:02:37 +00:00
|
|
|
browser: targetBrowser,
|
2022-03-24 13:56:42 +00:00
|
|
|
manifest: () => createManifest(targetBrowser),
|
2022-03-20 18:02:37 +00:00
|
|
|
webExtConfig,
|
2022-03-05 13:10:45 +00:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
root: sourceDir,
|
|
|
|
});
|