Repository navigation
Expand file tree
/
Copy pathwxt.config.ts
More file actions
120 lines (115 loc) · 4.06 KB
/
Copy pathwxt.config.ts
File metadata and controls
120 lines (115 loc) · 4.06 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import tailwindcss from '@tailwindcss/vite';
import type { Plugin } from 'vite';
import { defineConfig } from 'wxt';
/** Stable output path for Pierre's portable highlighter worker (see src/domains/diff/highlighting/worker.ts). */
const DIFF_WORKER_DEST = 'diff-highlighter-worker.js';
function tolerateNullCustomElements(): Plugin {
return {
name: 'tolerate-null-custom-elements',
transform(code, id) {
if (!/@pierre\/(diffs|trees)\/dist\/components\/web-components\.js/.test(id)) {
return;
}
return {
code: code
.replace(
'if (typeof HTMLElement !== "undefined" && customElements.get(DIFFS_TAG_NAME) == null) {',
'if (typeof HTMLElement !== "undefined" && globalThis.customElements != null && globalThis.customElements.get(DIFFS_TAG_NAME) == null) {',
)
.replace(
'if (typeof HTMLElement !== "undefined" && customElements.get(FILE_TREE_TAG_NAME) == null) {',
'if (typeof HTMLElement !== "undefined" && globalThis.customElements != null && globalThis.customElements.get(FILE_TREE_TAG_NAME) == null) {',
),
map: null,
};
},
};
}
export default defineConfig({
experimental: {
escapeUnicode: true,
},
modules: ['@wxt-dev/module-react', '@wxt-dev/auto-icons'],
// Auto-load local modules (relative paths in `modules` break on WXT 0.21 + Node).
modulesDir: 'src/modules',
srcDir: 'src',
outDir: 'dist',
hooks: {
// Copy Pierre's self-contained portable worker into the extension at a
// stable, same-origin path. Runs in both dev and build, so `new Worker()`
// works identically in `pnpm dev` and `pnpm build` (a bundled `?worker`
// would be served cross-origin from the dev server and fail to spawn).
'build:publicAssets'(_wxt, files) {
files.push({
absoluteSrc: fileURLToPath(import.meta.resolve('@pierre/diffs/worker/worker-portable.js')),
relativeDest: DIFF_WORKER_DEST,
});
},
},
autoIcons: {
baseIconPath: './assets/logo.png',
},
webExt: {
binaries: process.env.WXT_FIREFOX_BINARY
? { firefox: process.env.WXT_FIREFOX_BINARY }
: undefined,
},
manifest: {
version: '1.6.0',
name: 'diffy',
description: 'Browser extension for reviewing large PRs on GitHub',
permissions: ['storage', 'contextMenus'],
host_permissions: [
'https://api.github.com/*',
'https://github.com/*',
'https://fonts.googleapis.com/*',
'https://fonts.gstatic.com/*',
],
content_security_policy: {
// Overlay loads Shiki WASM plus Google Fonts for preset code/tree families.
// Do not set connect-src — it would block HMR (ws://localhost) and other runtime fetches.
extension_pages:
"script-src 'self' 'wasm-unsafe-eval'; object-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com;",
},
web_accessible_resources: [
{
resources: ['assets/*.js', 'overlay.html'],
matches: ['https://github.com/*'],
},
],
browser_specific_settings: {
gecko: {
id: 'diffy@suveshmoza.com',
data_collection_permissions: {
required: ['none'],
},
},
},
},
vite: () => ({
// Vite defaults to **/*.html; with outDir `dist` that also picks up built
// extension HTML and breaks dep scanning (UNRESOLVED_ENTRY under dist/).
optimizeDeps: {
entries: ['src/entrypoints/**/*.{html,ts,tsx}'],
},
resolve: {
alias: {
'@': resolve(import.meta.dirname, 'src'),
'@pierre/diffs/dist/style.js': resolve(
import.meta.dirname,
'node_modules/@pierre/diffs/dist/style.js',
),
'@pierre/diffs/theme-resolver': resolve(
import.meta.dirname,
'node_modules/@pierre/diffs/dist/highlighter/themes/themeResolver.js',
),
},
},
worker: {
format: 'es',
},
plugins: [tailwindcss(), tolerateNullCustomElements()],
}),
});