-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
140 lines (139 loc) · 4.38 KB
/
vite.config.ts
File metadata and controls
140 lines (139 loc) · 4.38 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
import path from 'path';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import tailwindcss from '@tailwindcss/vite';
import { VitePWA } from 'vite-plugin-pwa';
export default defineConfig(({ mode }) => {
return {
// GitHub Pages 部署路径
base: mode === 'production' ? '/cyclesync/' : '/',
server: {
port: 1234,
host: '0.0.0.0',
},
plugins: [
tailwindcss(),
react(),
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['icons/*.svg', 'icons/*.png'],
manifest: {
name: 'CycleSync - Smart Period Tracker',
short_name: 'CycleSync',
description: 'Smart period tracking with AI-powered predictions',
theme_color: '#f43f5e',
background_color: '#fff1f2',
display: 'standalone',
orientation: 'portrait',
scope: mode === 'production' ? '/cyclesync/' : '/',
start_url: mode === 'production' ? '/cyclesync/' : '/',
icons: [
{
src: 'icons/icon-48.png',
sizes: '48x48',
type: 'image/png',
purpose: 'any'
},
{
src: 'icons/icon-72.png',
sizes: '72x72',
type: 'image/png',
purpose: 'any'
},
{
src: 'icons/icon-96.png',
sizes: '96x96',
type: 'image/png',
purpose: 'any'
},
{
src: 'icons/icon-144.png',
sizes: '144x144',
type: 'image/png',
purpose: 'any'
},
{
src: 'icons/icon-192.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any'
},
{
src: 'icons/icon-512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any'
},
{
src: 'icons/icon-512-maskable.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable'
}
]
},
workbox: {
globPatterns: ['**/*.{js,css,html,svg,png,ico,woff,woff2}'],
runtimeCaching: [
// ESM.sh CDN - React 和核心依赖
{
urlPattern: /^https:\/\/esm\.sh\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'esm-sh-cache',
expiration: {
maxEntries: 50,
maxAgeSeconds: 60 * 60 * 24 * 30 // 30 days
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
// Google Fonts CSS
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365 // 1 year
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
// Google Fonts 字体文件
{
urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'gstatic-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365 // 1 year
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
]
}
})
],
define: {
// 不在构建时注入 API Key,用户需要在应用设置中输入自己的 Key
// 这样可以避免密钥泄露到公开的 JS 文件中
'process.env.API_KEY': JSON.stringify(''),
'process.env.GEMINI_API_KEY': JSON.stringify('')
},
resolve: {
alias: {
'@': path.resolve(__dirname, '.'),
}
}
};
});