forked from bitsocialhq/seedit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
203 lines (201 loc) · 5.52 KB
/
vite.config.js
File metadata and controls
203 lines (201 loc) · 5.52 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import { VitePWA } from 'vite-plugin-pwa';
import reactScan from '@react-scan/vite-plugin-react-scan';
const isProduction = process.env.NODE_ENV === 'production';
const isDevelopment = process.env.NODE_ENV === 'development';
export default defineConfig({
plugins: [
react({
babel: {
plugins: [
['babel-plugin-react-compiler', {
verbose: true
}]
]
}
}),
// Only include React Scan in development mode - never in production builds
(isDevelopment || (!isProduction && process.env.NODE_ENV !== 'production')) && reactScan({
showToolbar: true,
playSound: true,
}),
nodePolyfills({
globals: {
Buffer: true,
global: true,
process: true,
},
protocolImports: true,
include: ['crypto', 'stream', 'util', 'buffer', 'events'],
}),
VitePWA({
registerType: 'autoUpdate',
strategies: 'injectManifest',
injectManifest: {
maximumFileSizeToCacheInBytes: 20000000,
},
srcDir: 'src',
filename: 'sw.ts',
devOptions: {
enabled: true,
type: 'module',
},
includeAssets: ['favicon.ico', 'robots.txt', 'apple-touch-icon.png'],
manifest: {
name: 'Seedit',
short_name: 'Seedit',
description: 'A serverless, adminless, decentralized reddit alternative',
theme_color: '#ffffff',
background_color: '#ffffee',
display: 'standalone',
icons: [
{
src: '/android-chrome-192x192.png',
sizes: '192x192',
type: 'image/png'
},
{
src: '/android-chrome-512x512.png',
sizes: '512x512',
type: 'image/png'
},
{
src: '/android-chrome-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable'
}
]
},
workbox: {
clientsClaim: true,
skipWaiting: true,
cleanupOutdatedCaches: true,
navigateFallback: 'index.html',
navigateFallbackDenylist: [/^\/api/, /^\/_(.*)/],
maximumFileSizeToCacheInBytes: 6000000,
runtimeCaching: [
// Fix index.html not refreshing on new versions
{
urlPattern: ({ url }) => url.pathname === '/' || url.pathname === '/index.html',
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'html-cache'
}
},
// PNG caching
{
urlPattern: ({ url }) => url.pathname.endsWith('.png'),
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'images',
expiration: {
maxEntries: 50
}
}
},
// Add additional asset caching
{
urlPattern: /\.(?:js|css|woff2?|svg|gif|jpg|jpeg)$/,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'assets-cache',
expiration: {
maxEntries: 100,
maxAgeSeconds: 60 * 60 * 24 * 30 // 30 days
}
}
},
// Google Fonts caching
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365 // 365 days
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
{
urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-webfonts',
expiration: {
maxEntries: 30,
maxAgeSeconds: 60 * 60 * 24 * 365 // 365 days
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
]
}
}),
],
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
'node-fetch': 'isomorphic-fetch',
'assert': 'assert',
'stream': 'stream-browserify',
'crypto': 'crypto-browserify',
'buffer': 'buffer',
'util/': 'util',
'util': 'util',
},
},
server: {
port: 3000,
open: true,
watch: {
usePolling: true,
},
hmr: {
overlay: false
}
},
build: {
outDir: 'dist',
emptyOutDir: true,
sourcemap: process.env.GENERATE_SOURCEMAP === 'true',
target: process.env.ELECTRON ? 'electron-renderer' : 'esnext',
rollupOptions: {
output: {
manualChunks(id) {
if (/[\\/]node_modules[\\/](react|react-dom|react-router-dom|react-i18next|i18next|i18next-browser-languagedetector|i18next-http-backend)[\\/]/.test(id)) {
return 'vendor';
}
}
}
}
},
base: process.env.PUBLIC_URL || '/',
optimizeDeps: {
include: [
'ethers',
'assert',
'buffer',
'process',
'util',
'stream-browserify',
'isomorphic-fetch',
'workbox-core',
'workbox-precaching'
],
},
define: {
'process.env.VITE_COMMIT_REF': JSON.stringify(process.env.COMMIT_REF),
'global': 'globalThis',
'__dirname': '""',
}
});