-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvite.config.ts
122 lines (113 loc) · 3.13 KB
/
vite.config.ts
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
122
/// <reference types="vitest" />
import { defineConfig, UserConfigExport } from 'vite'
import react from '@vitejs/plugin-react'
import { crx, defineManifest } from '@crxjs/vite-plugin'
import tsconfigPaths from 'vite-tsconfig-paths'
import packageJson from './package.json'
const { version } = packageJson
const isDevToolsActive = process.env.VITE_DEV_TOOLS === 'true'
const versionName = process.env.GITHUB_REF_NAME || 'local'
// Convert from Semver (example: 0.1.0-beta6)
const [major, minor, patch] = version
// can only contain digits, dots, or dash
.replace(/[^\d.-]+/g, '')
// split into version parts
.split(/[.-]/)
.filter(Boolean)
const manifest = defineManifest(async () => {
const permissions: chrome.runtime.ManifestPermissions[] = [
'storage',
'tabs',
'offscreen',
'scripting',
'notifications',
'contextMenus',
'idle',
]
const matches = ['https://*/*', 'http://localhost/*', 'http://127.0.0.1/*']
if (isDevToolsActive) {
matches.push('http://*/*')
}
return {
manifest_version: 3,
name: 'Radix Wallet Connector',
version: `${major}.${minor}.${patch}`,
description:
'Only used with the Radix Wallet mobile app. Link Wallet Connector to your wallet to use dApps in Chrome, or use Ledger devices.',
version_name: version === '0.0.0' ? versionName : version,
action: {
default_popup: 'src/pairing/index.html',
},
background: {
service_worker: `src/chrome/background/background.ts`,
type: 'module',
},
content_scripts: [
{
matches,
js: ['src/chrome/content-script/content-script.ts'],
run_at: 'document_idle',
all_frames: true,
},
],
options_page: 'src/options/index.html',
host_permissions: matches,
permissions,
icons: {
'16': 'radix-icon_16x16.png',
'48': 'radix-icon_48x48.png',
'128': 'radix-icon_128x128.png',
},
}
})
const buildConfig: UserConfigExport = {
plugins: [react(), crx({ manifest }), tsconfigPaths()],
resolve: {
alias: {
stream: 'vite-compatible-readable-stream',
},
},
build: {
sourcemap: isDevToolsActive ? 'inline' : false,
rollupOptions: {
onwarn(warning, warn) {
if (warning.code === 'MODULE_LEVEL_DIRECTIVE') {
return
}
warn(warning)
},
input: {
options: 'src/options/index.html',
ledger: 'src/ledger/index.html',
pairing: 'src/pairing/index.html',
devTools: 'src/chrome/dev-tools/dev-tools.html',
offscreen: 'src/chrome/offscreen/index.html',
},
},
},
}
if (!isDevToolsActive) {
delete buildConfig.build.rollupOptions.input['devTools']
}
export default defineConfig({
...buildConfig,
// @ts-expect-error
test: {
globals: true,
environment: 'jsdom',
setupFiles: './src/setup-tests.ts',
reporters: [
'default',
[
'vitest-sonar-reporter',
{ outputFile: 'test-report.xml', silent: true },
],
],
coverage: {
reportsDirectory: './coverage',
provider: 'v8',
reporter: ['json', 'text', 'lcov', 'clover'],
include: ['src/**/*'],
},
},
})