Add build support for Chromium.
This commit is contained in:
parent
eb6407ef7e
commit
7b63504323
|
@ -5,8 +5,11 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "vite build -m development --watch",
|
"start": "vite build -m development --watch",
|
||||||
|
"start:chromium": "VITE_BROWSER=chromium pnpm start",
|
||||||
"clean": "trash build web-ext-artifacts",
|
"clean": "trash build web-ext-artifacts",
|
||||||
"build": "pnpm clean && vite build && web-ext build --source-dir build && pnpm zip-source",
|
"build": "pnpm clean && pnpm build:chromium && pnpm build:firefox && pnpm zip-source",
|
||||||
|
"build:chromium": "VITE_BROWSER=chromium vite build && web-ext build -n fangs-chromium-{version}.zip -s build/chromium",
|
||||||
|
"build:firefox": "VITE_BROWSER=firefox vite build && web-ext build -n fangs-firefox-{version}.zip -s build/firefox",
|
||||||
"zip-source": "git archive --format zip --output web-ext-artifacts/fangs-source.zip HEAD",
|
"zip-source": "git archive --format zip --output web-ext-artifacts/fangs-source.zip HEAD",
|
||||||
"test": "xo && stylelint 'source/**/*.scss' && tsc && c8 ava"
|
"test": "xo && stylelint 'source/**/*.scss' && tsc && c8 ava"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
|
import process from 'node:process';
|
||||||
import url from 'node:url';
|
import url from 'node:url';
|
||||||
|
|
||||||
import {defineConfig} from 'vite';
|
import {defineConfig} from 'vite';
|
||||||
|
@ -8,13 +9,30 @@ import {defineConfig} from 'vite';
|
||||||
import preactPreset from '@preact/preset-vite';
|
import preactPreset from '@preact/preset-vite';
|
||||||
import webExtension from 'vite-plugin-web-extension';
|
import webExtension from 'vite-plugin-web-extension';
|
||||||
|
|
||||||
const currentDir = path.dirname(url.fileURLToPath(import.meta.url));
|
const targetBrowser = process.env.VITE_BROWSER ?? 'firefox';
|
||||||
|
process.env.VITE_BROWSER = targetBrowser;
|
||||||
|
|
||||||
const buildDir = path.join(currentDir, 'build');
|
const currentDir = path.dirname(url.fileURLToPath(import.meta.url));
|
||||||
|
const buildDir = path.join(currentDir, 'build', targetBrowser);
|
||||||
const sourceDir = path.join(currentDir, 'source');
|
const sourceDir = path.join(currentDir, 'source');
|
||||||
|
|
||||||
// Create the Firefox profile if it doesn't already exist.
|
// Create the browser profile if it doesn't already exist.
|
||||||
fs.mkdirSync(path.join(currentDir, 'firefox'), {recursive: true});
|
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({
|
export default defineConfig({
|
||||||
build: {
|
build: {
|
||||||
|
@ -28,15 +46,9 @@ export default defineConfig({
|
||||||
// https://github.com/aklinker1/vite-plugin-web-extension
|
// https://github.com/aklinker1/vite-plugin-web-extension
|
||||||
webExtension({
|
webExtension({
|
||||||
assets: 'assets',
|
assets: 'assets',
|
||||||
browser: 'firefox',
|
browser: targetBrowser,
|
||||||
manifest: path.join(sourceDir, 'manifest.json'),
|
manifest: path.join(sourceDir, 'manifest.json'),
|
||||||
webExtConfig: {
|
webExtConfig,
|
||||||
browserConsole: true,
|
|
||||||
firefoxProfile: 'firefox/',
|
|
||||||
keepProfileChanges: true,
|
|
||||||
startUrl: 'about:debugging#/runtime/this-firefox',
|
|
||||||
target: 'firefox-desktop',
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
root: sourceDir,
|
root: sourceDir,
|
||||||
|
|
Loading…
Reference in New Issue