-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
98 lines (96 loc) · 3.25 KB
/
vite.config.ts
File metadata and controls
98 lines (96 loc) · 3.25 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
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { VitePWA } from 'vite-plugin-pwa'
import { resolve } from 'path'
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
return {
define: {
__APP_VERSION__: JSON.stringify(env.VITE_APP_VERSION ?? '1.0.0'),
},
plugins: [
react(),
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['favicon.svg', 'robots.txt'],
manifest: {
name: 'CF React Boilerplate',
short_name: 'CFReact',
description: 'Production-grade React app for Cloudflare Pages',
theme_color: '#0f62fe',
background_color: '#f4f4f4',
display: 'standalone',
start_url: '/',
icons: [
{ src: '/icons/icon-192.png', sizes: '192x192', type: 'image/png' },
{ src: '/icons/icon-512.png', sizes: '512x512', type: 'image/png' },
],
},
workbox: {
globPatterns: ['**/*.{js,css,html,svg,woff2}'],
navigateFallback: '/index.html',
navigateFallbackDenylist: [/^\/api/],
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: { maxEntries: 10, maxAgeSeconds: 31536000 },
cacheableResponse: { statuses: [0, 200] },
},
},
{
urlPattern: /^https:\/\/jsonplaceholder\.typicode\.com\/.*/i,
handler: 'NetworkFirst',
options: {
cacheName: 'api-cache',
expiration: { maxEntries: 50, maxAgeSeconds: 300 },
networkTimeoutSeconds: 10,
},
},
],
},
}),
],
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
'@app': resolve(__dirname, 'src/app'),
'@pages': resolve(__dirname, 'src/pages'),
'@components': resolve(__dirname, 'src/components'),
'@features': resolve(__dirname, 'src/features'),
'@hooks': resolve(__dirname, 'src/hooks'),
'@services': resolve(__dirname, 'src/services'),
'@store': resolve(__dirname, 'src/store'),
'@styles': resolve(__dirname, 'src/styles'),
'@utils': resolve(__dirname, 'src/utils'),
},
},
build: {
target: 'esnext',
minify: 'esbuild',
sourcemap: false,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules/react') || id.includes('node_modules/react-dom') || id.includes('node_modules/react-router-dom')) {
return 'vendor'
}
if (id.includes('node_modules/zustand')) {
return 'store'
}
},
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
},
},
chunkSizeWarningLimit: 500,
},
optimizeDeps: {
include: ['react', 'react-dom', 'react-router-dom', 'zustand'],
},
server: { port: 3000, strictPort: true },
}
})