-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvite.config.iwa.ts
128 lines (118 loc) · 3.31 KB
/
vite.config.iwa.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
123
124
125
126
127
128
import type { KeyObject } from 'node:crypto'
import { Buffer } from 'node:buffer'
import { writeFileSync, writeSync } from 'node:fs'
import path, { join, resolve, toNamespacedPath } from 'node:path'
import process from 'node:process'
import { fileURLToPath, URL } from 'node:url'
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
import vue from '@vitejs/plugin-vue'
import webbundle from 'rollup-plugin-webbundle'
import UnoCSS from 'unocss/vite'
import { defineConfig, loadEnv } from 'vite'
import * as wbnSign from 'wbn-sign'
import pkgJSON from './package.json'
const TEMPLATE = {
name: 'DualSense Tester',
short_name: 'DualSense Tester',
display_override: [
'window-controls-overlay',
],
display: 'standalone',
scope: '/',
start_url: '/',
version: pkgJSON.version,
icons: [
{
src: '/pwa/android-chrome-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: '/pwa/android-chrome-512x512.png',
sizes: '512x512',
type: 'image/png',
},
],
permissions_policy: {
'hid': ['self'],
'direct-sockets': ['self'],
'cross-origin-isolated': ['self'],
},
}
function tidy(str: string) {
return str.replace(/\s+/g, ' ').trim()
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
let signKey: KeyObject | undefined
const wbnSignPlugin: ReturnType<typeof webbundle>[] = []
if (env.VITE_WBN_PRIVATE_KEY) {
signKey = wbnSign.parsePemKey(
env.VITE_WBN_PRIVATE_KEY as any,
env.VITE_WBN_PASSPHRASE,
)
writeFileSync('public/.well-known/manifest.webmanifest', JSON.stringify(TEMPLATE))
wbnSignPlugin.push(
webbundle({
baseURL: new wbnSign.WebBundleId(
signKey,
).serializeWithIsolatedWebAppOrigin(),
static: { dir: 'public' },
output: 'signed.swbn',
integrityBlockSign: {
strategy: new wbnSign.NodeCryptoSigningStrategy(signKey),
},
headerOverride: {
'cross-origin-embedder-policy': 'require-corp',
'cross-origin-opener-policy': 'same-origin',
'cross-origin-resource-policy': 'same-origin',
'content-security-policy':
tidy(`base-uri \'none\';
default-src \'self\';
object-src \'none\';
frame-src \'self\' https: blob: data:;
connect-src \'self\' https: wss:;
script-src \'self\' \'wasm-unsafe-eval\';
img-src \'self\' https: blob: data:;
media-src \'self\' https: blob: data:;
font-src \'self\' blob: data:;
style-src \'self\' \'unsafe-inline\';
require-trusted-types-for \'script\';
`),
},
}),
)
}
return ({
plugins: [
vue({
script: {
defineModel: true,
},
}),
UnoCSS(),
VueI18nPlugin({
include: [path.resolve(__dirname, './src/locales/**.json')],
strictMessage: false,
}),
...wbnSignPlugin,
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
build: {
outDir: 'dist_iwa',
},
server: {
port: 4321,
hmr: {
protocol: 'ws',
host: 'localhost',
clientPort: 4321,
},
},
})
})