-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathvite.config.ts
More file actions
104 lines (102 loc) · 3.27 KB
/
vite.config.ts
File metadata and controls
104 lines (102 loc) · 3.27 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
import { readFileSync } from 'node:fs';
import { sentryVitePlugin } from '@sentry/vite-plugin';
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
const pkg = JSON.parse(readFileSync('./package.json', 'utf-8')) as { version: string };
const sentryAuthToken = process.env.SENTRY_AUTH_TOKEN;
const sentryOrg = process.env.SENTRY_ORG;
const sentryProject = process.env.SENTRY_PROJECT;
const sentryEnabled = Boolean(sentryAuthToken && sentryOrg && sentryProject);
export default defineConfig({
plugins: [
react(),
tailwindcss(),
VitePWA({
registerType: 'autoUpdate',
injectRegister: false,
manifestFilename: 'manifest.json',
includeAssets: ['favicon.png', 'icon-512.png', 'robots.txt'],
manifest: {
id: '/',
name: 'D.I.G.E. - Dijiang Integrated Generator Efficiency',
short_name: 'D.I.G.E.',
description: 'Thermal Pool power generation optimizer for Arknights: Endfield.',
start_url: '/',
scope: '/',
display: 'standalone',
display_override: ['standalone', 'minimal-ui'],
background_color: '#1a1a2e',
theme_color: '#1a1a2e',
orientation: 'any',
lang: 'zh-CN',
dir: 'ltr',
categories: ['games', 'utilities'],
icons: [
{
src: '/favicon.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any maskable',
},
{
src: '/icon-512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable',
},
],
},
workbox: {
navigateFallback: '/index.html',
globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2,json}'],
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
cleanupOutdatedCaches: true,
skipWaiting: true,
clientsClaim: true,
},
devOptions: {
enabled: false,
},
}),
sentryEnabled
? sentryVitePlugin({
org: sentryOrg,
project: sentryProject,
authToken: sentryAuthToken,
release: { name: pkg.version },
sourcemaps: {
filesToDeleteAfterUpload: ['./dist/**/*.map'],
},
})
: null,
].filter(Boolean),
build: {
sourcemap: true,
rollupOptions: {
output: {
manualChunks(id: string) {
if (id.includes('i18n') && (id.includes('locales') || id.endsWith('.json')))
return 'i18n';
if (id.includes('node_modules')) {
if (id.includes('@sentry/') || id.includes('react-microsoft-clarity'))
return 'monitoring';
if (
(id.includes('node_modules/react/') || id.includes('node_modules/react-dom/')) &&
!id.includes('react-chartjs') &&
!id.includes('@sentry')
)
return 'core';
if (id.includes('chart.js') || id.includes('react-chartjs')) return 'vendor';
if (id.includes('@iconify/react')) return 'vendor';
if (id.includes('qrcode.react')) return 'vendor';
}
},
},
},
},
define: {
__APP_VERSION__: JSON.stringify(pkg.version),
},
});