2022-03-05 13:10:45 +00:00
|
|
|
import fs from 'node:fs';
|
2022-03-20 20:52:53 +00:00
|
|
|
import fsp from 'node:fs/promises';
|
2022-03-05 13:10:45 +00:00
|
|
|
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';
|
|
|
|
|
|
|
|
const currentDir = path.dirname(url.fileURLToPath(import.meta.url));
|
|
|
|
const sourceDir = path.join(currentDir, 'source');
|
|
|
|
|
2022-03-21 09:44:18 +00:00
|
|
|
const queueVersion = '0.2.5';
|
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;
|
|
|
|
|
|
|
|
let webExtConfig;
|
|
|
|
|
|
|
|
if (targetBrowser === 'chromium') {
|
|
|
|
fs.mkdirSync(path.join(currentDir, 'chromium'), {recursive: true});
|
|
|
|
webExtConfig = {
|
|
|
|
browserConsole: true,
|
|
|
|
chromiumProfile: 'chromium/',
|
|
|
|
keepProfileChanges: true,
|
|
|
|
startUrl: 'chrome://extensions/',
|
|
|
|
target: 'chromium',
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
fs.mkdirSync(path.join(currentDir, 'firefox'), {recursive: true});
|
|
|
|
webExtConfig = {
|
|
|
|
browserConsole: true,
|
|
|
|
firefoxProfile: 'firefox/',
|
|
|
|
keepProfileChanges: true,
|
|
|
|
startUrl: 'about:debugging#/runtime/this-firefox',
|
|
|
|
target: 'firefox-desktop',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const buildDir = path.join(currentDir, 'build', targetBrowser);
|
2022-03-05 13:10:45 +00:00
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
build: {
|
2022-03-17 13:03:08 +00:00
|
|
|
minify: true,
|
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-20 20:52:53 +00:00
|
|
|
async manifest() {
|
|
|
|
const manifest = JSON.parse(
|
|
|
|
await fsp.readFile(
|
|
|
|
path.join(sourceDir, `${targetBrowser}-manifest.json`),
|
|
|
|
// eslint-disable-next-line unicorn/prefer-json-parse-buffer
|
|
|
|
'utf-8',
|
|
|
|
),
|
|
|
|
) as Record<string, unknown>;
|
|
|
|
|
|
|
|
manifest.version = queueVersion;
|
|
|
|
|
|
|
|
return manifest;
|
|
|
|
},
|
2022-03-20 18:02:37 +00:00
|
|
|
webExtConfig,
|
2022-03-05 13:10:45 +00:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
root: sourceDir,
|
|
|
|
});
|