Repository navigation
Expand file tree
/
Copy pathvite.config.mjs
More file actions
143 lines (131 loc) · 4.16 KB
/
Copy pathvite.config.mjs
File metadata and controls
143 lines (131 loc) · 4.16 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import fs from 'node:fs'
import posthog from '@posthog/rollup-plugin'
import react from '@vitejs/plugin-react-swc'
import { defineConfig, loadEnv } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'
const pkg = JSON.parse(
fs.readFileSync(new URL('./package.json', import.meta.url), 'utf-8'),
)
export const getPosthogSourcemapConfig = ({ command, env = {} }) => {
if (command !== 'build') return null
const uploadFlag =
env.POSTHOG_UPLOAD_SOURCEMAPS ??
process.env.POSTHOG_UPLOAD_SOURCEMAPS ??
'false'
if (String(uploadFlag).toLowerCase() !== 'true') return null
const personalApiKey = env.POSTHOG_API_KEY || process.env.POSTHOG_API_KEY
const projectId = env.POSTHOG_PROJECT_ID || process.env.POSTHOG_PROJECT_ID
const host = env.POSTHOG_HOST || process.env.POSTHOG_HOST
if (!personalApiKey || !projectId || !host) return null
return { personalApiKey, projectId, host }
}
export const shouldUploadPosthogSourcemaps = options =>
Boolean(getPosthogSourcemapConfig(options))
// https://vitejs.dev/config/
export default ({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const posthogSourcemapConfig = getPosthogSourcemapConfig({
command,
env: { ...process.env, ...env },
})
return defineConfig({
define: {
'import.meta.env.VITE_APP_VERSION': JSON.stringify(pkg.version),
},
// Strip console.* / debugger from production bundles only, so dev logging
// is untouched. `command` is 'build' for `vite build`, 'serve' for the dev server.
esbuild: {
drop: command === 'build' ? ['console', 'debugger'] : [],
},
plugins: [
react(),
...(posthogSourcemapConfig
? [
posthog({
...posthogSourcemapConfig,
sourcemaps: {
deleteAfterUpload: true,
},
}),
]
: []),
VitePWA({
includeAssets: [
'favicon.ico',
'robots.txt',
'apple-touch-icon.png',
'safari-pinned-tab.svg',
'mstile-150x150.png',
],
injectManifest: {
globIgnores: ['index.html'],
globPatterns: ['**/*.{js,css,html,png,svg}'],
},
manifest: {
background_color: '#ffffff',
display: 'standalone',
icons: [
{
sizes: '192x192',
src: '/android-chrome-192x192.png',
type: 'image/png',
},
{
sizes: '512x512',
src: '/android-chrome-512x512.png',
type: 'image/png',
},
{
sizes: '64x64',
src: 'pwa-64x64.png',
type: 'image/png',
},
{
sizes: '192x192',
src: 'pwa-192x192.png',
type: 'image/png',
},
{
sizes: '512x512',
src: 'pwa-512x512.png',
type: 'image/png',
},
{
purpose: 'maskable',
sizes: '512x512',
src: 'maskable-icon-512x512.png',
type: 'image/png',
},
],
name: 'Donetick: Simplify Tasks & Chores, Together.',
short_name: 'Donetick',
theme_color: '#ffffff',
},
registerType: 'prompt',
workbox: {
// The PWA plugin runs after PostHog's upload/cleanup stage, so prevent
// it from leaving separate service-worker source maps in dist.
sourcemap: false,
maximumFileSizeToCacheInBytes: 6000000, // 6MB
//Exclude API and Swagger routes from service worker navigation fallback
navigateFallback: '/index.html',
navigateFallbackDenylist: [
/^\/api\//, // Exclude all API routes
/^\/swagger/, // Exclude all Swagger routes
],
// Do not use skipWaiting/clientsClaim with the prompt flow. The new
// worker activates only after the user accepts the in-app update.
skipWaiting: false,
},
}),
],
resolve: {
alias: [
{
find: '@',
replacement: '/src',
},
],
},
})
}