-
-
Notifications
You must be signed in to change notification settings - Fork 316
Expand file tree
/
Copy pathwxt.config.ts
More file actions
121 lines (116 loc) · 4.39 KB
/
wxt.config.ts
File metadata and controls
121 lines (116 loc) · 4.39 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
121
import path from "node:path"
import process from "node:process"
import { defineConfig } from "wxt"
const WXT_API_KEY_PATTERN = /^WXT_.*API_KEY/
const ALLOWED_BUNDLED_API_KEYS = new Set([
"WXT_POSTHOG_API_KEY",
])
// See https://wxt.dev/api/config.html
export default defineConfig({
srcDir: "src",
imports: false,
modules: ["@wxt-dev/module-react", "@wxt-dev/i18n/module"],
manifestVersion: 3,
// WXT top level alias - will be automatically synced to tsconfig.json paths and Vite alias
alias: process.env.WXT_USE_LOCAL_PACKAGES === "true"
? {
"@read-frog/definitions": path.resolve(__dirname, "../read-frog-monorepo/packages/definitions/src"),
"@read-frog/api-contract": path.resolve(__dirname, "../read-frog-monorepo/packages/api-contract/src"),
}
: {},
manifest: ({ mode, browser }) => ({
name: "__MSG_extName__",
description: "__MSG_extDescription__",
default_locale: "en",
// Fixed extension ID for development
...(mode === "development" && (browser === "chrome" || browser === "edge") && {
key: "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw2KhiXO2vySZtPu5pNSbyKhYavh8Be7gXmCZt8aJf6tQ/L3JK0qzL+3JSc/o20td3Jw+B2Dcw+EI93NAZr24xKnTNXQiJpuIuHb8xLXD0Ra/HrTVi4TJIhPdESogoG4uL6CD/F3TxfZJ2trX4Bt9cdAw1RGGeU+xU0g+YFfEka4ZUCpFAmTEw9H3/DU+nCp8yGaJWyiVgCTcFe38GZKEPt0iMJkTw956wz/iiafLx0pNG/RaztG9cAPoQOD2+SMFaeQ+b/G4OG17TYhzb09AhNBl6zSJ3jTKHSwuedCFwCce8Q/EchJfQZv71mjAE97bzwvkDYPCLj31Z5FE8HntMwIDAQAB",
}),
permissions: [
"storage",
"tabs",
"alarms",
"cookies",
"contextMenus",
"identity",
"scripting",
"webNavigation",
...(browser !== "firefox" ? ["offscreen"] : []),
],
host_permissions: [
"*://*/*", // Required for scripting.executeScript in any frame
],
// Allow images/SVGs referenced by content-script UI <img> tags to be loaded from
// moz-extension:// URLs on regular pages. Firefox enforces this more strictly.
web_accessible_resources: [
{
resources: ["assets/*.png", "assets/*.svg", "assets/*.webp"],
matches: ["*://*/*", "file:///*"],
},
],
// Firefox-specific settings for MV3
...(browser === "firefox" && {
// Override default CSP to exclude `upgrade-insecure-requests` (Firefox MV3 default),
// which would upgrade custom provider HTTP URLs (e.g. LAN) to HTTPS.
content_security_policy: {
extension_pages: "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';",
},
browser_specific_settings: {
gecko: {
id: "{bd311a81-4530-4fcc-9178-74006155461b}",
strict_min_version: "112.0",
data_collection_permissions: {
required: ["none"],
optional: ["technicalAndInteraction"],
},
},
},
}),
}),
zip: {
includeSources: [".env.production"],
excludeSources: ["docs/**/*", "assets/**/*", "repos/**/*"],
},
dev: {
server: {
port: 3333,
},
},
vite: configEnv => ({
plugins: configEnv.mode === "production"
? [
{
name: "check-api-key-env",
buildStart() {
const apiKeyVars = Object.keys(process.env)
.filter(key => WXT_API_KEY_PATTERN.test(key))
.filter(key => !ALLOWED_BUNDLED_API_KEYS.has(key))
if (apiKeyVars.length > 0) {
throw new Error(
`\n\nFound WXT_*_API_KEY environment variables that may be bundled:\n`
+ `${apiKeyVars.map(k => ` - ${k}`).join("\n")}\n\n`
+ `Please unset these variables before building for production.\n`,
)
}
// Check required env vars only for zip builds
if (process.env.WXT_ZIP_MODE) {
const requiredEnvVars = [
"WXT_GOOGLE_CLIENT_ID",
"WXT_POSTHOG_API_KEY",
"WXT_POSTHOG_HOST",
]
const missing = requiredEnvVars.filter(key => !process.env[key])
if (missing.length > 0) {
throw new Error(
`\n\nMissing required environment variables for zip:\n`
+ `${missing.map(k => ` - ${k}`).join("\n")}\n\n`
+ `Set them in .env.production or your environment.\n`,
)
}
}
},
},
]
: [],
}),
})