-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathwxt.config.ts
More file actions
115 lines (107 loc) · 4.28 KB
/
Copy pathwxt.config.ts
File metadata and controls
115 lines (107 loc) · 4.28 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
import tailwindcss from '@tailwindcss/vite'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { analyzer } from 'vite-bundle-analyzer'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import svgLoader from 'vite-svg-loader'
import { defineConfig } from 'wxt'
import { Browser } from 'wxt/browser'
import { version } from './package.json'
import { EXTENSION_SHORT_NAME } from './utils/constants'
type ManifestPermissions = Browser.runtime.ManifestPermissions | (string & Record<never, never>)
export const VERSION = version.split('-')[0]
const IS_FIREFOX = process.argv.includes('firefox')
const IS_DEV = import.meta.env.NODE_ENV === 'development'
const FIREFOX_EXTENSION_ID = '{48e0818d-6c94-43d4-9465-61ceb28080e3}'
const ENABLE_BUNDLE_ANALYZER = process.argv.includes('--analyze') || process.env.ANALYZE === 'true'
const permissionsForChrome: ManifestPermissions[] = ['system.memory']
const permissionsForFirefox: ManifestPermissions[] = ['menus']
const permissionsForDev: ManifestPermissions[] = ['declarativeNetRequestFeedback']
const extraPermissions: ManifestPermissions[] = [
...(IS_FIREFOX ? permissionsForFirefox : permissionsForChrome),
...(IS_DEV ? permissionsForDev : []),
]
const svgLoaderPlugin = svgLoader({
svgoConfig: {
multipass: true,
plugins: [
{
name: 'preset-default',
params: {
overrides: {
// @see https://github.com/svg/svgo/issues/1128
removeViewBox: false,
cleanupIds: {
minify: false,
remove: false,
},
},
},
},
'prefixIds',
],
},
})
svgLoaderPlugin.enforce = 'pre'
svgLoaderPlugin.name = 'svg-loader'
// See https://wxt.dev/api/config.html
export default defineConfig({
imports: false,
modules: ['@wxt-dev/module-vue'],
webExt: {
chromiumArgs: ['--user-data-dir=./.wxt/chrome-data'],
},
zip: {
artifactTemplate: '{{name}}-{{packageVersion}}-{{browser}}-{{mode}}.zip',
},
exposeWebResources: {
paths: ['/assets/*.woff2', '/fonts/*.woff2', '/content-scripts/*.css', '/main-world-injected.js'],
},
vite: (_env) => {
return {
build: {
target: ['chrome124', 'firefox120', 'safari16'],
// firefox does't support js file larger than 5MB, so we exclude @mlc-ai/web-llm from the bundle (which firefox does not use)
rollupOptions: { external: IS_FIREFOX ? ['@mlc-ai/web-llm', '@huggingface/transformers'] : undefined },
},
plugins: [
nodePolyfills(),
analyzer({ enabled: ENABLE_BUNDLE_ANALYZER }),
vueJsx({ babelPlugins: ['@babel/plugin-proposal-explicit-resource-management'] }),
tailwindcss(),
svgLoaderPlugin,
],
}
},
manifest: {
name: IS_FIREFOX ? '__MSG_extNameFirefox__' : '__MSG_extName__',
short_name: EXTENSION_SHORT_NAME,
description: IS_FIREFOX ? '__MSG_extDescFirefox__' : '__MSG_extDesc__',
version: VERSION,
default_locale: 'en',
permissions: IS_FIREFOX ? ['declarativeNetRequest', 'tabs', 'storage', 'scripting', 'contextMenus', 'unlimitedStorage', 'webNavigation', ...extraPermissions] : ['declarativeNetRequest', 'tabs', 'storage', 'scripting', 'contextMenus', 'sidePanel', 'unlimitedStorage', 'webNavigation', ...extraPermissions],
minimum_chrome_version: '124',
declarative_net_request: IS_FIREFOX ? { rule_resources: [{ id: 'ruleset_1', enabled: true, path: 'rules.json' }] } : undefined,
content_security_policy: {
extension_pages: `script-src 'self' 'wasm-unsafe-eval'; object-src 'self';`,
},
// Include the action manifest key to ensure the toolbar button (in the top-right corner) is clickable in Firefox
action: IS_FIREFOX ? { default_title: EXTENSION_SHORT_NAME } : undefined,
// Opera supports sidebar_action, while Chrome ignores that field
sidebar_action: {
default_title: EXTENSION_SHORT_NAME,
default_panel: 'sidepanel.html',
open_at_install: true,
},
browser_specific_settings: IS_FIREFOX ? { gecko: { id: FIREFOX_EXTENSION_ID } } : undefined,
content_scripts: [
{
matches: ['<all_urls>'],
js: ['/main-world-injected.js'],
run_at: 'document_start',
world: 'MAIN',
},
],
host_permissions: ['*://*/*', 'ws://*/*', 'wss://*/*'],
optional_host_permissions: ['<all_urls>'],
},
})