-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
156 lines (148 loc) · 3.93 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
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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { VitePWA } from 'vite-plugin-pwa'
import fs from 'fs'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
VitePWA({
registerType: 'autoUpdate',
includeAssets: [
'favicon.ico',
'apple-touch-icon.png',
'ChinALE_96_any.png',
'ChinALE_192_any.png',
'ChinALE_512_any.png',
'ChinALE_96_maskable.png',
'ChinALE_192_maskable.png',
'ChinALE_512_maskable.png'
],
manifest: {
name: 'ChinALE',
short_name: 'ChinALE',
description: 'Unlock Chinese Metadata, Bridge AVID World.',
theme_color: '#171717',
background_color: '#171717',
display: 'standalone',
id: "/?source=pwa",
start_url: '/?source=pwa',
scope: '/',
orientation: 'any',
categories: ['productivity', 'utilities'],
icons: [
{
src: 'apple-touch-icon.png',
sizes: '180x180',
type: 'image/png'
},
{
src: 'ChinALE_96_any.png',
sizes: '96x96',
type: 'image/png',
purpose: 'any'
},
{
src: 'ChinALE_192_any.png',
sizes: '192x192',
type: 'image/png',
purpose: 'any'
},
{
src: 'ChinALE_512_any.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any'
},
{
src: 'ChinALE_96_maskable.png',
sizes: '96x96',
type: 'image/png',
purpose: 'maskable'
},
{
src: 'ChinALE_192_maskable.png',
sizes: '192x192',
type: 'image/png',
purpose: 'maskable'
},
{
src: 'ChinALE_512_maskable.png',
sizes: '512x512',
type: 'image/png',
purpose: 'maskable'
}
]
},
workbox: {
// 启用 SW 立即接管网页
skipWaiting: true,
clientsClaim: true,
// 静态资源缓存模式 - 扩展匹配模式以包含所有静态资源
globPatterns: [
'**/*.{js,css,html,ico,png,svg,woff2,jpg,jpeg,gif,json,webp}'
],
// 运行时缓存策略
runtimeCaching: [
{
// CDN 资源缓存策略
urlPattern: /^https:\/\/cdnjs\.cloudflare\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'cdn-cache',
expiration: {
maxEntries: 20,
maxAgeSeconds: 60 * 60 * 24 * 365 // 1 year
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
]
}
})
],
// 构建优化配置
build: {
sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom']
}
}
},
chunkSizeWarningLimit: 1000
},
// 路径别名配置
resolve: {
alias: {
'@': '/src',
'@components': '/src/components',
'@assets': '/src/assets'
}
},
// 开发服务器配置
server: {
// HTTPS 配置
https: {
key: fs.readFileSync('localhost-key.pem'),
cert: fs.readFileSync('localhost.pem'),
},
// 安全头配置 - 简化为静态网站所需
headers: {
'Content-Security-Policy': [
"default-src 'self'",
"script-src 'self' 'unsafe-inline' cdnjs.cloudflare.com",
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob:",
"font-src 'self'"
].join('; '),
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'X-XSS-Protection': '1; mode=block',
'Referrer-Policy': 'strict-origin-when-cross-origin'
}
}
})