forked from ScottyLabs/cmueats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
122 lines (111 loc) · 3.17 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
import { defineConfig, loadEnv } from 'vite';
import { checker } from 'vite-plugin-checker';
import { VitePWA, VitePWAOptions } from 'vite-plugin-pwa'
import react from '@vitejs/plugin-react-swc';
import viteTsconfigPaths from 'vite-tsconfig-paths';
import svgrPlugin from 'vite-plugin-svgr';
import jwt from 'jsonwebtoken';
const manifestForPlugin: Partial<VitePWAOptions> = {
registerType: "prompt",
includeAssets: ["favicon.ico", "/favicons/apple-touch-icon.png"],
manifest: {
"short_name": "CMUEats",
"name": "CMUEats",
"icons": [
{
"src": "/favicons/android-chrome-192x192.png",
"type": "image/png",
"sizes": "192x192",
"purpose": "any"
},
{
"src": "/favicons/android-chrome-512x512.png",
"type": "image/png",
"sizes": "512x512",
"purpose": "any"
},
{
"src": "/favicons/android-chrome-192x192-maskable.png",
"type": "image/png",
"sizes": "192x192",
"purpose": "maskable"
},
{
"src": "/favicons/android-chrome-512x512-maskable.png",
"type": "image/png",
"sizes": "512x512",
"purpose": "maskable"
}
],
"scope": "/",
"start_url": "/",
"display": "standalone",
"theme_color": "#ffffff",
"background_color": "#ffffff"
},
};
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const teamId = env.MAPKIT_JS_TEAM_ID;
const keyId = env.MAPKIT_JS_KEY_ID;
const authKey = env.MAPKIT_JS_AUTH_KEY;
const tokenEnvVariable =
env.MAPKIT_JS_TOKEN_ENV_VARIABLE || 'MAPKIT_JS_TOKEN';
const ttl = +(env.MAPKIT_JS_TTL || 31_536_000); // 1 year
const origin = env.MAPKIT_JS_ORIGIN || env.DEPLOY_PRIME_URL;
console.log(teamId, keyId, authKey, tokenEnvVariable, ttl)
if (!teamId || !keyId || !authKey || !tokenEnvVariable || !ttl) {
console.error('Missing mandatory parameters');
process.exit(1);
}
const iat = Date.now() / 1000;
const payload = {
iat,
exp: iat + ttl,
iss: teamId,
origin,
};
const header = {
typ: 'JWT',
alg: 'ES256',
kid: keyId,
};
try {
const token = jwt.sign(payload, atob(authKey), { header });
env[tokenEnvVariable] = token;
// eslint-disable-next-line no-console
console.info({
title: 'MapKit JS token generated successfully',
summary: `Origin: ${origin}, expires in ${ttl} seconds.`,
text: `process.env.${tokenEnvVariable} = '${token}';`,
});
} catch (error) {
console.error(error);
process.exit(1);
}
return {
define: {
'process.env.VITE_MAPKITJS_TOKEN': JSON.stringify(env[tokenEnvVariable]),
},
build: {
outDir: 'build',
},
plugins: [
react(),
viteTsconfigPaths(),
svgrPlugin(),
VitePWA({
manifest: manifestForPlugin,
registerType: 'autoUpdate',
// Enables autoupdate (uses new version after user quits and reloads app)
workbox: {
cleanupOutdatedCaches: true,
skipWaiting: true,
},
}),
checker({
typescript: true,
}),
],
};
});