-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
115 lines (107 loc) · 2.63 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
import { defineConfig } from 'vite';
import generateFile from 'vite-plugin-generate-file';
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer';
import { ManifestOptions, VitePWA } from 'vite-plugin-pwa';
const buildTime = new Date();
const manifest: Partial<ManifestOptions> = {
theme_color: '#eebbff',
background_color: '#111111',
display: 'fullscreen',
orientation: 'landscape',
start_url: '/chrono-sleuth/',
id: 'com.amcolash.chrono-sleuth',
name: 'Chrono Sleuth',
short_name: 'Chrono Sleuth',
description: 'Chrono Sleuth is a detective game set in a mysterious town.',
icons: [
{
src: './favicon.webp',
sizes: 'any',
type: 'image/webp',
purpose: 'any maskable',
},
],
};
export default defineConfig({
base: './',
build: {
rollupOptions: {
output: {
manualChunks: {
phaser: ['phaser'],
},
},
},
// TODO: Is this the right choice?
// This removes comments (licenses)
minify: 'terser',
terserOptions: {
compress: {
passes: 2,
},
mangle: true,
format: {
comments: false,
},
},
},
server: {
watch: {
ignored: ['**/src-tauri/**'],
},
},
define: {
__BUILD_TIME__: buildTime,
__TAURI__: process.env.TAURI_PLATFORM !== undefined,
},
plugins: [
// Only include PWA plugin if not building for Tauri
process.env.TAURI_PLATFORM === undefined && [
// Inject SW registration in main.ts - only when building for web
{
name: 'injectServiceWorker',
transform(code, id) {
if (id.endsWith('src/main.ts')) {
return `import { registerSW } from "virtual:pwa-register";
registerSW({ immediate: true });
${code}`;
}
return code;
},
},
VitePWA({
// TODO: Is this the right choice?
registerType: 'autoUpdate',
workbox: {
maximumFileSizeToCacheInBytes: 20 * 1000 * 1000, // 20mb
globPatterns: ['**/*.{js,css,html,png,jpg,jpeg,webp,svg,gif,ttf,m4a,mp3}'],
},
manifest,
devOptions: {
// Enable to have service worker/manifest in dev mode
// enabled: true,
},
}),
generateFile([
{
type: 'json',
output: './build.json',
data: { buildTime },
},
]),
],
ViteImageOptimizer({
png: {
quality: 50,
},
jpg: {
quality: 40,
},
jpeg: {
quality: 40,
},
cache: true,
cacheLocation: 'node_modules/.cache/vite-plugin-image-optimizer',
}),
],
});