Build extension targets into separate output directories
Chrome and Firefox shared extension/build and each build set emptyOutDir, so building one target clobbered the other's output and left the wrong manifest behind. Emit each target into extension/build/<target> and write the copied manifest into Vite's resolved output directory (via configResolved) so the two cannot drift apart. Point the Firefox web-ext scripts (ext:serve, ext:lint, ext:dev) at extension/build/firefox.
This commit is contained in:
4 files changed
+21
-18
No files matched your search
@@ -22,7 +22,7 @@
|
||||
- `app/routes/` & `app/templates/`: Route definitions and `.gjs` templates.
|
||||
- `app/styles/`: Application styles and Tailwind entry points.
|
||||
- `doc/`: Protocol notes and integration specifications.
|
||||
- `extension/`: Chrome/Firefox MV3 manifests; `extension/build/` is generated output.
|
||||
- `extension/`: Chrome/Firefox MV3 manifests; `extension/build/<target>/` is generated output.
|
||||
- `tests/`: QUnit tests (`tests/integration/` for `.gjs` components, `tests/unit/` for services).
|
||||
|
||||
## Commands
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
## Browser Extension
|
||||
|
||||
Dashtab is a Manifest V3 browser extension that overrides the new tab. It can also run as a plain web app via `pnpm start`, but that path exists only for development convenience. `vite.config.mjs` switches to relative asset paths and copies the target manifest into `extension/build/` when `DASHTAB_EXT=1`, with `DASHTAB_EXT_TARGET` selecting `chrome` or `firefox`. Never edit `extension/build/` by hand.
|
||||
Dashtab is a Manifest V3 browser extension that overrides the new tab. It can also run as a plain web app via `pnpm start`, but that path exists only for development convenience. `vite.config.mjs` switches to relative asset paths and copies the target manifest into `extension/build/<target>/` when `DASHTAB_EXT=1`, with `DASHTAB_EXT_TARGET` selecting `chrome` or `firefox`. Never edit `extension/build/` by hand.
|
||||
|
||||
- **Manifests**: `extension/manifest.chrome.json` and `extension/manifest.firefox.json`. Extension ids are pinned (Chrome `key`, Firefox `browser_specific_settings.gecko.id`) so `identity.getRedirectURL()` stays stable.
|
||||
- **Auth transport**: `app/auth/transport.js` feature-detects the identity API (`app/utils/extension.js`). The extension uses `identity.launchWebAuthFlow` + `getRedirectURL`; the dev-server build (no identity API) falls back to a full-page redirect to the provider callback. See `doc/extension_auth.md`.
|
||||
|
||||
@@ -46,14 +46,15 @@ production: requests go out with the extension's host permissions and
|
||||
authorizations use the browser's `identity.launchWebAuthFlow`.
|
||||
|
||||
- `pnpm ext:build:firefox` / `pnpm ext:build:chrome` build the app into
|
||||
`extension/build/` with the matching `extension/manifest.<browser>.json`.
|
||||
`extension/build/firefox/` and `extension/build/chrome/` respectively, with
|
||||
the matching `extension/manifest.<browser>.json`.
|
||||
- `pnpm ext:dev` rebuilds on change and launches Firefox via `web-ext`
|
||||
(dedicated temporary profile). Changes reload the add-on rather than using HMR.
|
||||
- `pnpm ext:serve` runs `web-ext` against an existing `extension/build/`.
|
||||
- `pnpm ext:serve` runs `web-ext` against an existing `extension/build/firefox/`.
|
||||
- Load manually: `about:debugging#/runtime/this-firefox` → **Load Temporary
|
||||
Add-on…** → select `extension/build/manifest.json` (Firefox), or
|
||||
`chrome://extensions` → **Load unpacked** → `extension/build/` (Chrome).
|
||||
- `pnpm ext:lint` validates the packaged extension.
|
||||
Add-on…** → select `extension/build/firefox/manifest.json` (Firefox), or
|
||||
`chrome://extensions` → **Load unpacked** → `extension/build/chrome/` (Chrome).
|
||||
- `pnpm ext:lint` validates the packaged Firefox extension.
|
||||
|
||||
The extension IDs are pinned (`key` in the Chrome manifest, `browser_specific_settings.gecko.id`
|
||||
in the Firefox manifest) so the OAuth redirect URL is stable. See
|
||||
|
||||
+3
-3
@@ -15,9 +15,9 @@
|
||||
"ext:build": "DASHTAB_EXT=1 DASHTAB_EXT_TARGET=firefox vite build --mode development",
|
||||
"ext:build:chrome": "DASHTAB_EXT=1 DASHTAB_EXT_TARGET=chrome vite build --mode development",
|
||||
"ext:build:firefox": "DASHTAB_EXT=1 DASHTAB_EXT_TARGET=firefox vite build --mode development",
|
||||
"ext:dev": "concurrently -k \"DASHTAB_EXT=1 DASHTAB_EXT_TARGET=firefox vite build --mode development --watch\" \"wait-on extension/build/manifest.json && pnpm ext:serve\"",
|
||||
"ext:lint": "web-ext lint --source-dir=extension/build",
|
||||
"ext:serve": "web-ext run --source-dir=extension/build --start-url about:newtab",
|
||||
"ext:dev": "concurrently -k \"DASHTAB_EXT=1 DASHTAB_EXT_TARGET=firefox vite build --mode development --watch\" \"wait-on extension/build/firefox/manifest.json && pnpm ext:serve\"",
|
||||
"ext:lint": "web-ext lint --source-dir=extension/build/firefox",
|
||||
"ext:serve": "web-ext run --source-dir=extension/build/firefox --start-url about:newtab",
|
||||
"format": "prettier . --cache --write",
|
||||
"lint": "concurrently \"pnpm:lint:*(!fix)\" --names \"lint:\" --prefixColors auto",
|
||||
"lint:css": "stylelint \"**/*.css\"",
|
||||
|
||||
+10
-8
@@ -4,6 +4,7 @@ import { babel } from '@rollup/plugin-babel';
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
import corsAnywhere from 'cors-anywhere';
|
||||
import { copyFileSync, mkdirSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const CORS_PROXY_HOST = '127.0.0.1';
|
||||
@@ -39,22 +40,23 @@ function corsProxyPlugin() {
|
||||
|
||||
// Emits the target browser's manifest into the extension build output so the
|
||||
// packaged app can be loaded as an unpacked extension or linted with web-ext.
|
||||
// The manifest is written into Vite's resolved output directory so the two
|
||||
// cannot drift apart.
|
||||
function extensionManifestPlugin(target) {
|
||||
let outDir;
|
||||
return {
|
||||
name: 'dashtab-extension-manifest',
|
||||
apply: 'build',
|
||||
configResolved(config) {
|
||||
outDir = config.build.outDir;
|
||||
},
|
||||
closeBundle() {
|
||||
const buildDir = fileURLToPath(
|
||||
new URL('./extension/build', import.meta.url),
|
||||
);
|
||||
mkdirSync(buildDir, { recursive: true });
|
||||
mkdirSync(outDir, { recursive: true });
|
||||
copyFileSync(
|
||||
fileURLToPath(
|
||||
new URL(`./extension/manifest.${target}.json`, import.meta.url),
|
||||
),
|
||||
fileURLToPath(
|
||||
new URL('./extension/build/manifest.json', import.meta.url),
|
||||
),
|
||||
join(outDir, 'manifest.json'),
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -70,7 +72,7 @@ export default defineConfig(() => {
|
||||
base: isExtension ? './' : '/',
|
||||
build: isExtension
|
||||
? {
|
||||
outDir: 'extension/build',
|
||||
outDir: `extension/build/${target}`,
|
||||
emptyOutDir: true,
|
||||
target: 'es2022',
|
||||
// MV3 forbids inline scripts; opting out of the polyfill keeps the
|
||||
|
||||
Reference in new issue
Block a user